javascript - XSS fix for JSON in JSP page -


during static analysis getting xss vulnerability in jsp code. forwarding request jsp page servlet. requets contains json string. in jsp page, retrieving appid value json object. use appid value retrive further info using xhr calls.

<script type="text/javascript"> var appid; // appcontext json string var appcontextstr=<%=request.getparameter("appcontext")%>; // xss vulenrability detected  if(appcontextstr!= null || !appcontextstr.equals("")){ appid= appcontextstr.appid; } </script> 

how address xss issue?

you can urlencode <%=request.getparameter("appcontext")%> before assigning appcontextstr, if value not meant have non-alphanumeric symbols.

the vulnerability fire if (not user himself) can specify appcontext value like

"asdsa; alert('busted')" evil javascript instead of alert()

that said, not user-controlled json exploitable yet static analysis tools stil whine remote possibilities.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -