SChandan516395 (Community Member) asked a question.

How to fix CWE 601: Open Redirects for Javascript

Hi ,

I see there are a lot of sanitization methods in AntiXSS library to fix Open Redirects for Server side component.

Im looking for an API or an approach to fix this for javascript code.

image 

Please assist.

Thank you .

 

 


  • Hi @SChandan516395 (Community Member)​,

     

    Veracode Static Analysis reports CWE 601 ('Open Redirect') when it can see that you take potentially user-controlled data (e.g. from the URL) and redirect to it. The concern being an attacker might be able to craft a URL that goes to your page first and then redirects to a phishing page.

     

    In your example, it seems to me that you are checking if the last character of the URL is '#'. If that is the case, you redirect to the same URL minus the '#'. I don't see how this can lead to an Open Redirect and recommend that you propose a mitigation by design for this and discuss it with your organization's Security Team. For more information on how to propose a mitigation, please refer to our Help Center: https://docs.veracode.com/r/improve_mitigation

     

    Thank you,

    Florian Walter

    Expand Post
  • SChandan516395 (Community Member)

    Thanks Florian for the feedback.

    Is it possible that URL can have an evil javascript method ?

     

     

    • Yes, this is actually little known, but besides e.g. HTTP, HTTPS, FTP, etc., another valid URL is `javascript:`. This means that e.g. `javascript:alert(5)` is a valid URL that would execute the JavaScript (in this case, simply create an alert box as a proof of concept).

       

      As a matter of fact, frameworks like React are actively trying to deprecate this functionality ("A future version of React will block javascript: URLs as a security precaution") as it is not really needed anymore but is the reason for many security issues.

      Expand Post

Topics (4)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.