Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Fortify HP found a header manipulation vulnerability in my basic CorsFilter:

HttpServletResponse response = (HttpServletResponse) res;
        String origin = ((HttpServletRequest)req).getHeader("origin");


and i get the header manipulation here:
response.setHeader("Access-Control-Allow-Origin", origin);




Any ideas?

What I have tried:

I tried this:
if (origin != null) {
            origin = origin.replace("\n", "");
            origin = origin.replace("\r", "");
        }


but the issue persists.
Posted
Updated 18-Oct-19 4:44am

Mark it as Not an issue in Fortify and move on
 
Share this answer
 
The whole point of CORS is to restrict which sites can access your resources.
Cross-Origin Resource Sharing (CORS) - HTTP | MDN[^]

Your code is effectively saying that any site can access your resources. But there's already a way to do that, without relying on headers passed from the client:
Java
response.setHeader("Access-Control-Allow-Origin", "*");
Access-Control-Allow-Origin - HTTP | MDN[^]

NB: You should carefully review the security implications of this setting.
 
Share this answer
 
Comments
Lakyme 22-Oct-19 5:28am    
We allow credentials, so "*" is not an option :(
Be aware that by reflecting the "origin" in the Access-Control-Allow-Origin and using Access-Control-Allow-Credentials, you are essentially allowing third party applications visited by your users to make these requests and reading the results. If said results are confidential, this is a concern.

This is not exactly what Fortify is really warning you about, but an issue to consider none the less.

Please refer to What is CORS (cross-origin resource sharing)? Tutorial & Examples[^] , under "Server-generated ACAO header from client-specified Origin header"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900