XSS - Ajax调用返回字符串赋值给jsp上的java脚本变量

时间:2017-11-28 09:10:43

标签: ajax jsp xss

我找到解决方案几天,如何修复从ajax调用返回的易受攻击的java脚本变量。

 public String getDefaultCopyName(HttpServletRequest request, HttpServletResponse response,
     Long serviceGroupId) {
  MeoOptimizationSet set = service.find(serviceGroupId);
  String name = set.getName() + getCopySuffix();
  return name;
´}

  var defaultName = '';
  $.ajax({
     url: "<c:url value='/MeoOptimizationSet-getDefaultCopyName.mvc'/>", 
     data: { serviceGroupId: selectedIds[0] },
     success: function(data) {<b> defaultName = data</b>},
     async: false
  });

  APP.confirm({
  msg: "<br>"+label + "<br><br><input type='text' id='newName' size='40' 
  value='" + <b> defaultName </br> + "'  />",
  ok: function() {
    //TODO
     });
  }
  }

1 个答案:

答案 0 :(得分:0)

我的任务非常简单,只是我想知道从JSP到java控制器的ajax调用,Controller方法向JSPajax调用方法返回一些值,我将值赋值给java脚本变量

var defaultName = '';
   $.ajax({
       url: "/abc.mvc", 
       data: { id: 1001},
       success: function (data) {
       defaultName = data
     }
  });

var defaultName = ''; $.ajax({ url: "/abc.mvc", data: { id: 1001}, success: function (data) { defaultName = data } });

如何保护跨站点脚本(XSS)中的dafalutName分配?