
cng168336 (Community Member) asked a question.
location.href = url;

cng168336 (Community Member) asked a question.
Ask the Community
Get answers, share a use case, discuss your favorite features, or get input from the community.
By clicking “Accept All Cookies”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts.
.png)
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising.
Hi,
The reason CWE-80 may be reported is because if the variable "url" is tainted with untrusted data, it may be possible to execute JavaScript in the client's browser. It is unclear from the snippet where the data originates, but for instance, assume "url" equals "javascript:alert(1)", then when location.href is set to "url", the client's browser will then execute "alert(1)". This example is not exhaustive as there are other URI schemes that can also introduce issues. In this instance it is recommended to validate that the URL conforms to an expected format such as HTTPS and that untrusted elements that construct the URL are sanitized before use. Keep in mind that simply checking that a URL is an expected scheme such as HTTPS does not remediate all risk, as the risk for CWE-601 open redirects may still be possible if compensating controls are not in place.
If you have any other questions, I would recommend you schedule a consultation call to discuss, https://help.veracode.com/r/t_schedule_consultation , or you can send an email to Support@veracode.com with the application and scan name so we can look into the identified flaw to provide you more specific feedback.
Regards,
Veracode Application Security Consulting Team
"The reason CWE-80 may be reported is because if the variable "url" is tainted with untrusted data, it may be possible to execute JavaScript in the client's browser".
Thanks for that explanation. Can I suggest that text like this be added to the description that gets attached to the findings? The current description talks only about http responses, which is very confusing when the scanner is flagging a js line that modifies window.location. Or perhaps this should be a separate CWE with its own description.
I tried to use Angular DomSanitizer sanitizer() function to process the URL before passing it to location.href but now I get this error:
Attack Vector: ng.platformBrowser.DomSanitizer.sanitize
Number of Modules Affected: 1
Description: This call to ng.platformBrowser.DomSanitizer.sanitize() contains a cross-site scripting (XSS) flaw. The application populates the HTTP response with untrusted input, allowing an attacker to embed malicious content, such as Javascript code, which will be executed in the context of the victim's browser. XSS vulnerabilities are commonly exploited to steal or manipulate cookies, modify presentation of content, and compromise confidential information, with new attack vectors being discovered on a regular basis.
I thought sanitize() should prevent the embedded Javascript code from being executed? What's the proper fixes for this?
Hi,
While this is a valid control to defend against this flaw category (if using the correct context!), Veracode Static Analysis currently does not recognize the DomSanitizer sanitizer function ( https://angular.io/api/platform-browser/DomSanitizer#sanitize ) as a Supported Cleansing Function ( https://help.veracode.com/r/review_cleansers ) yet.
I would recommend proposing a mitigation, you can find more information on how to do this here: https://help.veracode.com/r/improve_mitigation .
After proposing the mitigation you need to contact your security team to request approval.
Please let us know if you have any remaining questions or concerns.
Regards,
Veracode Application Security Consulting Team
Hi @cng168336 (Community Member) ,
We are actively looking into supporting the DomSanitizer, however we have no definite date at this time.
To subscribe to updates for our Veracode Static Analysis product you can subscribe in the Notifications Settings ( you can find more information on where to find this in the Veracode Platform here: https://help.veracode.com/r/t_configure_emails).
I would recommend proposing a mitigation, you can find more information on how to do this here: https://help.veracode.com/r/improve_mitigation .
After proposing the mitigation you need to contact your security team to request approval.
Thank you,
Boy Baukema
@Boy, Security Consultant (Veracode) ,
So in future will Vera code support Angular's DomSanitizer? or we need to check some other way to fix this vulnerability.
Hi @vkr536186 (Community Member) ,
We are actively looking into supporting the DomSanitizer, however we have no definite date at this time.
To subscribe to updates for our Veracode Static Analysis product you can subscribe in the Notifications Settings ( you can find more information on where to find this in the Veracode Platform here: https://help.veracode.com/r/t_configure_emails ).
For now I would recommend proposing a mitigation, you can find more information on how to do this here: https://help.veracode.com/r/improve_mitigation .
After proposing the mitigation you need to contact your security team to request approval.
Thank you,
Boy Baukema
Hi @vkr536186 (Community Member) - to stay updated on new capabilities of the Veracode products, you can also follow #NewsThursday (https://community.veracode.com/s/topic/0TO2T000000c0DAWAY/newsthursday) where we share the updates from the release note every Thursday. By following this topic (clicking on the follow button, and then toggle notification besides the follow button) you will receive email notifications on every new post under this topic. Hope this helps 🙂
This vulnerability occurs when user-supplied data is not properly validated, encoded, or sanitized before being included in dynamic HTML content.