Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
Prevent cross-site scripting from url

How to prevent xss attack from this tag in my website: <%=request.getParameter("errorMsg")%> as this is rendering user input via url in error page above code snippet is present in a error.jsp file.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Replace the JSP expression

<%= request.getParameter("errorMsg") %>

with the JSTL tag c:out as

<c:out value="${param.errorMsg}" />

This will prevent cross-site scripting attacks by escaping any <html> markup injected in the request parameter through replacement of special characters, like <, >, with their equivalent HTML entities &lt;, &gt;, etc.

Make sure to add the JSTL core tag library to your error.jsp using the taglib directive as

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

Edit: (in response to OP's comment)

Your code has a bug, it will throw a NullPointerException because encodedValue is null.

Replace it with the static method URLEncoder.encode(request.getParameter("errorMsg"), "UTF-8") instead. Then make sure ErrorHTTPSession.jsp too uses the c:out tag to print this errorMsg and you should be good then.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!