Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Grails-在检索i18n消息时防止XSS_Javascript_Grails_Xss - Fatal编程技术网

Javascript Grails-在检索i18n消息时防止XSS

Javascript Grails-在检索i18n消息时防止XSS,javascript,grails,xss,Javascript,Grails,Xss,我正在使用messageSource访问服务层中的i18n属性,以便在发生错误时向用户提供反馈 messageSource.getMessage('validation.my.code',args,defaultLocale) 结果被推送到flash范围(info或error)中,并作为json返回到浏览器,并在jQuery中处理,如下所示 $.ajax({ type: 'POST', url: 'update', data: formData, success:

我正在使用messageSource访问服务层中的i18n属性,以便在发生错误时向用户提供反馈

messageSource.getMessage('validation.my.code',args,defaultLocale)

结果被推送到flash范围(info或error)中,并作为json返回到浏览器,并在jQuery中处理,如下所示

$.ajax({
    type: 'POST',
    url: 'update',
    data: formData,
    success: function (data) {
        // do stuff
        showMessage({info: data.info, error: data.error});
    }
})
我的问题是,当传递给messageSource的arg显示用户输入时,例如“'johndoe'用户名已被使用”,就有可能发生XSS攻击。 我在Config.groovy中的编码设置如下,因为它会破坏应用程序的其他部分(如果更严格的话)

codecs {
  expression = 'html' // escapes values inside ${}
  scriptlet = 'none' // escapes output from scriptlets in GSPs
  taglib = 'none' // escapes output from taglibs
  staticparts = 'none' // escapes output from static template parts
}
我想知道是否有一种优雅的方式来处理json的返回,而不必手动提交我自己的解决方案

编辑:更多详细信息

只需将以下内容放入UI表单上的相关输入字段,即可攻击上述内容:

<script>alert('hello');</script>
alert('hello');
通过以下方法在服务层中进行验证:

private List<String> validate(def domainObject) {
    def messages = []
    if (!domainObject.validate()) {
       messages = domainObject.errors.allErrors.collect {
       // the error objects implement MessageSourceResolvable  
       simpleMessageSource.getMessage(it, args, defaultLocale)   
    }
    messages
}
私有列表验证(def domainObject){
def消息=[]
如果(!domainObject.validate()){
messages=domainObject.errors.allErrors.collect{
//错误对象实现MessageSourceResolvable
simpleMessageSource.getMessage(it、args、defaultLocale)
}
信息
}
输入被传递到args方法,成为返回给用户的错误字符串的一部分,并最终作为json输出回浏览器。
当然,最终会出现一个JavaScript弹出窗口,说“你好”.

关于文档:grails默认情况下通过解码输入值来拒绝XSS数据包

对不起,我不明白你指的是什么,你能详细说明一下吗?我想你的意思是grails已经内置了机制来清理反射回用户的数据,这些机制可以在Config.groovy中配置问题,根据我的应用程序要求,我必须保持这些设置相当宽松。您可以拒绝此选项并使用“.encodeAsURL(),因为我记得它应该可以帮助您或删除所有(inputString,”)。您可以使用它。希望我能很好地理解您。您还可以补充一下,您是如何攻击此选项的