【问题标题】:Appending / at the end of the URL renders the same page?在 URL 的末尾附加 / 会呈现相同的页面?
【发布时间】:2015-09-11 12:35:31
【问题描述】:

考虑sn-p:

@Controller
@RequestMapping(value = "/spitter")
public class SpittrController {

    @RequestMapping(value = "/register", method = RequestMethod.GET)
    public String showRegistrationForm() {

        return "registerForm";
    }
}

registerForm.jsp 就这么简单:

<form method="post">
        <table>
            <tr>
                <td>First Name:</td>
                <td><input type="text" name="firstName" /></td>
            </tr>
            <tr>
                <td>Last Name:</td>
                <td><input type="text" name="lastName" /></td>
            </tr>
            <tr>
                <td>User Name:</td>
                <td><input type="text" name="userName" /></td>
            </tr>
            <tr>
                <td>Password:</td>
                <td><input type="password" name="password" /></td>
            </tr>
            <tr>

                <td><input type="submit" value="Register" /></td>
            </tr>
        </table>
</form>

当我在网络浏览器中输入以下 URL 时:

http://localhost:8080/web/spitter/注册

我在下面看到这个页面,这很好,根据功能:

现在,如果我稍微修改一下 URL,然后做这样的事情

http://localhost:8080/web/spitter/注册/

然后同样的页面也会被渲染,

为什么?即使输入的 address(URL) 没有指向 在控制器中映射的请求

有什么建议吗?

编辑:

当我必须使用 Spring Security 时,整个问题就出现了。

考虑sn-p:

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.formLogin().and().authorizeRequests().antMatchers("/spitter/")
            .authenticated().antMatchers(HttpMethod.GET, "/spitter/register")
            .authenticated();
    }

现在,当用户在浏览器中输入此内容时,

http://localhost:8080/web/spitter/注册

他被重定向到登录页面以验证自己,而

http://localhost:8080/web/spitter/注册/

不会将他重定向到登录页面,这是一个安全漏洞。 我必须将这个条目添加到

antMatchers(HttpMethod.GET, "/spitter/register/").authenticated()

除了

antMatchers(HttpMethod.GET, "/spitter/register").authenticated()

有什么方法可以解决这个问题,否则它会加倍努力只是附加 / 只是为了重定向到登录页面? p>

【问题讨论】:

标签: spring-mvc url


【解决方案1】:

试试这个模式

/spitter/register/**

【讨论】:

    猜你喜欢
    • 2011-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-16
    • 2012-06-20
    • 2023-03-30
    • 1970-01-01
    • 2013-04-02
    相关资源
    最近更新 更多