-
Notifications
You must be signed in to change notification settings - Fork 31
fix: Fix issue processing URLs for fetch and XHR requests. #783
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,18 +14,27 @@ function authorityUrlFilter(url: string): string { | |
| // This will work in browser environments, but in the future we may want to consider an approach | ||
| // which doesn't rely on the browser's URL parsing. This is because other environments we may | ||
| // want to target, such as ReactNative, may not have as robust URL parsing. | ||
| const urlObj = new URL(url); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was failing with relative URLs. |
||
| let hadAuth = false; | ||
| if (urlObj.username) { | ||
| urlObj.username = 'redacted'; | ||
| hadAuth = true; | ||
| } | ||
| if (urlObj.password) { | ||
| urlObj.password = 'redacted'; | ||
| hadAuth = true; | ||
| } | ||
| if (hadAuth) { | ||
| return urlObj.toString(); | ||
| // We first check if the URL can be parsed, because it may not include the base URL. | ||
| try { | ||
| // If the URL includes a protocol, if so, then it can probably be parsed. | ||
| // Credentials require a full URL. | ||
| if (url.includes('://')) { | ||
| const urlObj = new URL(url); | ||
| let hadAuth = false; | ||
| if (urlObj.username) { | ||
| urlObj.username = 'redacted'; | ||
| hadAuth = true; | ||
| } | ||
| if (urlObj.password) { | ||
| urlObj.password = 'redacted'; | ||
| hadAuth = true; | ||
| } | ||
| if (hadAuth) { | ||
| return urlObj.toString(); | ||
| } | ||
| } | ||
| } catch { | ||
| // Could not parse the URL. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a very basic approach. I already had some notes up above to come back to this and make it more flexible. Unfortuntely |
||
| } | ||
| // If there was no auth information, then we don't need to modify the URL. | ||
| return url; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger can potentially be used earlier in the process now.