0

i create a web form with JSP, and for preventing attacks I do the following:

input.replace("<", "something else");
input.replace(">", "something else");

so a user cannot add HTML or other tags inside a form.

Is this enough to prevent attacks of this kind(Insertions of HTML or other tags inside my website)??

Thanks you JH. G.

Jh. G.
  • 3
  • 1
  • What if someone then fills in `<script>alert('got you!')</script>` so they can attack the system that gets this data AFTER yours? – Marc B May 24 '11 at 17:13

2 Answers2

3

In short, no. I recommend that you should checkout the ESAPI project for this. They have built in tools to HTML encode requests and responses as to prevent XSS attacks.

CtrlDot
  • 2,463
  • 14
  • 11
0

This is not entirely the right way. It's not only incomplete as ', " and & also needs to be escaped, but you should actually be using JSTL <c:out> or fn:escapeXml() to escape HTML/XML entities in the view side.

E.g.

<c:out value="${bean.value}" />
<input type="text" name="foo" value="${fn:escapeXml(param.foo)}" />

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555