简体   繁体   English

如何在JSP中安全使用getParameter

[英]How to use getParameter in jsp the safe way

I'm using getParameter to get content from URL to the page. 我正在使用getParameter从URL到页面获取内容。

<p>name <%= request.getParameter("name") %></p>


What content schould I avoid (ex. script tags)? 我应该避免什么内容(例如脚本标签)?
How should I validate it? 我应该如何验证?

I'm working in JSP. 我在JSP中工作。

EDIT: 编辑:
For today I just strip html tags: 今天,我只去除html标签:

variable.replaceAll("\\<.*?>","");

You should not use scriptlet in jsp its not good practise 您不应该在jsp中使用scriptlet,这不是一个好习惯

<p>name <c:out value='${param.name}'/> </p>

you should take care of XSS attack c:out will escape xml 您应该注意XSS攻击 c:out将逃脱xml

To escape javascript injection you can Use StringUtils.escapejavaScript() 要逃脱JavaScript注入,可以使用StringUtils.escapejavaScript()

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

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