fix: validate protocol scheme names in setAsDefaultProtocolClient#50141
Merged
MarshallOfSound merged 1 commit intomainfrom Mar 9, 2026
Merged
fix: validate protocol scheme names in setAsDefaultProtocolClient#50141MarshallOfSound merged 1 commit intomainfrom
setAsDefaultProtocolClient#50141MarshallOfSound merged 1 commit intomainfrom
Conversation
On Windows, `app.setAsDefaultProtocolClient(protocol)` directly concatenates the protocol string into the registry key path with no validation. A protocol name containing `\` could write to an arbitrary subkey under `HKCU\Software\Classes\`, potentially hijacking existing protocol handlers. To fix this, add `Browser::IsValidProtocolScheme()` which validates that a protocol name conforms to the RFC 3986 scheme grammar: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) This rejects backslashes, forward slashes, whitespace, and any other characters not permitted in URI schemes.
deepak1556
approved these changes
Mar 9, 2026
Comment on lines
+88
to
+95
| for (size_t i = 1; i < scheme.size(); ++i) { | ||
| const char c = scheme[i]; | ||
| if (!base::IsAsciiAlpha(c) && !base::IsAsciiDigit(c) && c != '+' && | ||
| c != '-' && c != '.') { | ||
| LOG(ERROR) << "Protocol scheme contains invalid character: '" << c << "'"; | ||
| return false; | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
minor nit: should we simplify the loop similar to https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/external_protocol/auto_launch_protocols_policy_handler.cc;l=37-40 ?
|
Release Notes Persisted
|
This was referenced Mar 9, 2026
Contributor
|
I have automatically backported this PR to "41-x-y", please check out #50155 |
Contributor
|
I have automatically backported this PR to "39-x-y", please check out #50156 |
Contributor
|
I have automatically backported this PR to "38-x-y", please check out #50157 |
Contributor
|
I have automatically backported this PR to "40-x-y", please check out #50158 |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
On Windows,
app.setAsDefaultProtocolClient(protocol)directly concatenates the protocol string into the registry key path with no validation. A protocol name containing\could write to an arbitrary subkey underHKCU\Software\Classes\, potentially hijacking existing protocol handlers.To fix this, add
Browser::IsValidProtocolScheme()which validates that a protocol name conforms to the RFC 3986 scheme grammar:This rejects backslashes, forward slashes, whitespace, and any other characters not permitted in URI schemes.
Checklist
npm testpassesRelease Notes
Notes: Added validation to protocol client methods to reject protocol names that do not conform to the RFC 3986 URI scheme grammar.