How to fix Trust Boundary Violation flaw in Java Web application

user1782009 picture user1782009 · Feb 20, 2013 · Viewed 26.1k times · Source

I am receiving a Trust Boundary Violation from Veracode. My code is

userName= req.getParameter(Constant.USERNAME);
session.setAttribute(Constant.USERNAME, userName); //At this line i am getting Trust Boundry Violation flaw.

How can I validate userName to avoid a trust boundary violation flaw?

Answer

John Smith picture John Smith · Feb 20, 2013

Simply use a regular expression to validate the userName according to the rules your usernames follow:

if(userName.matches("[0-9a-zA-Z_]+")
     session.setAttribute(Constant.USERNAME, userName);