简体   繁体   English

如何修复 JSP 表达式标签中的跨站点脚本 (XSS)

[英]How to fix Cross Site Scripting (XSS) in JSP expression Tags

I am not sure how to fix cross site scripting (persistent) for scriptlet tags in Jsp's For example我不知道如何修复 Jsp 中 scriptlet 标签的跨站点脚本(持久性)例如

<%=value%> "/> I am also attaching a image that has scriptlet examples i am not sure how to fix those, please help me in fixing by proving some fixes enter image description here <%=value%> "/> 我还附上了一个包含 scriptlet 示例的图像,我不知道如何修复这些示例,请通过证明一些修复来帮助我修复,在此处输入图像描述

you can control by your framework configuration.您可以通过您的框架配置进行控制。 in Spring Security Framework use following code( https://docs.spring.io/spring-security/site/docs/current/reference/html/headers.html#headers-xss-protection ):在 Spring Security Framework 中使用以下代码( https://docs.spring.io/spring-security/site/docs/current/reference/html/headers.html#headers-xss-protection ):

Some browsers have built in support for filtering out reflected XSS attacks.一些浏览器内置了对过滤反射 XSS 攻击的支持。 This is by no means foolproof, but does assist in XSS protection.这绝不是万无一失的,但确实有助于 XSS 保护。

The filtering is typically enabled by default, so adding the header typically just ensures it is enabled and instructs the browser what to do when a XSS attack is detected.过滤通常默认启用,因此添加标头通常只是确保启用它并指示浏览器在检测到 XSS 攻击时执行什么操作。 For example, the filter might try to change the content in the least invasive way to still render everything.例如,过滤器可能会尝试以侵入性最小的方式更改内容以仍然呈现所有内容。 At times, this type of replacement can become a XSS vulnerability in itself.有时,这种类型的替换本身就可能成为 XSS 漏洞。 Instead, it is best to block the content rather than attempt to fix it.相反,最好阻止内容而不是尝试修复它。 To do this we can add the following header:为此,我们可以添加以下标题:

X-XSS-Protection: 1; mode=block

This header is included by default.默认情况下包含此标头。 However, we can customize it if we wanted.但是,我们可以根据需要对其进行自定义。 For example:例如:

<http>
    <!-- ... -->

    <headers>
        <xss-protection block="false"/>
    </headers>
</http>

Similarly, you can customize XSS protection within Java Configuration with the following:同样,您可以使用以下内容在 Java 配置中自定义 XSS 保护:

@EnableWebSecurity
public class WebSecurityConfig extends
WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
        // ...
        .headers()
            .xssProtection()
                .block(false);
    }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM