-
Notifications
You must be signed in to change notification settings - Fork 26.4k
fix(security): add URL validation to sanitization bypass functions to prevent infinite restart loops + comment typo #62387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
check to avoid application crash
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
signed to CLA! |
Hi, |
Yesterday I spent the whole evening and night dealing with an issue in my Angular app. In the end, I discovered that bypassSanitizationTrustResourceUrl was trying to bypass a URL that was actually just a normal string and not a valid URL, which caused everything to crash... So the edit in that repo was aimed at triggering a real error—or at least printing a warning—when trying to bypass a URL that isn't actually valid. |
This is odd because |
i will send you the public version of the repo with the error. -> https://github.com/k-i-o/AngularCrashDemonstration (bad repo without style but the problem is visible) |
… prevent infinite restart loops + comment typo
This isn't a sanitization issue. You're self-loading your app recursively in your iframe by having an URL that isn't external. |
I'm not sure I fully understand what you're saying — do you mean that if I comment out the iframe but keep the sanitization, the error will go away? |
Yes, your issue is that the iframe is loading your own app if you don't give it a full url. Any other string is considered a relative path, hence recursively loading your app. |
|
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
Current problematic behavior:
bypassSanitizationTrustResourceUrl()
receives an invalid URL string, the application crashes silentlyReproduction steps:
bypassSanitizationTrustResourceUrl('not-a-valid-url')
What is the new behavior?
New improved behavior:
bypassSanitizationTrustUrl()
: Validates URL format and blocks dangerous protocolsbypassSanitizationTrustResourceUrl()
: Stricter validation with allowed protocols whitelistbypassSanitizationTrustScript()
: Basic XSS pattern detectionbypassSanitizationTrustStyle()
: CSS injection pattern detectionbypassSanitizationTrustHtml()
: Input validationKey improvements:
Example error messages:
Does this PR introduce a breaking change?
No breaking changes: This fix only adds validation that throws errors for inputs that would have crashed the application anyway. Valid inputs continue to work exactly as before.
Other information
Why this fix is critical:
Testing considerations:
Real-world impact:
This fix addresses a common developer frustration where a simple typo in a URL can cause the entire development environment to become unusable, forcing developers to hunt through potentially hundreds of files to find the problematic bypass call.