Skip to content

fix: validate protocol scheme names in setAsDefaultProtocolClient#50141

Merged
MarshallOfSound merged 1 commit intomainfrom
validate-protocol-scheme
Mar 9, 2026
Merged

fix: validate protocol scheme names in setAsDefaultProtocolClient#50141
MarshallOfSound merged 1 commit intomainfrom
validate-protocol-scheme

Conversation

@codebytere
Copy link
Copy Markdown
Member

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 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.

Checklist

Release Notes

Notes: Added validation to protocol client methods to reject protocol names that do not conform to the RFC 3986 URI scheme grammar.

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.
@codebytere codebytere added semver/patch backwards-compatible bug fixes target/38-x-y PR should also be added to the "38-x-y" branch. target/39-x-y PR should also be added to the "39-x-y" branch. target/40-x-y PR should also be added to the "40-x-y" branch. target/41-x-y PR should also be added to the "41-x-y" branch. labels Mar 9, 2026
@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label 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;
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarshallOfSound MarshallOfSound enabled auto-merge (squash) March 9, 2026 16:21
@MarshallOfSound MarshallOfSound merged commit c264402 into main Mar 9, 2026
79 of 80 checks passed
@MarshallOfSound MarshallOfSound deleted the validate-protocol-scheme branch March 9, 2026 18:16
@release-clerk
Copy link
Copy Markdown

release-clerk bot commented Mar 9, 2026

Release Notes Persisted

Added validation to protocol client methods to reject protocol names that do not conform to the RFC 3986 URI scheme grammar.

@trop
Copy link
Copy Markdown
Contributor

trop bot commented Mar 9, 2026

I have automatically backported this PR to "41-x-y", please check out #50155

@trop trop bot added the in-flight/41-x-y label Mar 9, 2026
@trop
Copy link
Copy Markdown
Contributor

trop bot commented Mar 9, 2026

I have automatically backported this PR to "39-x-y", please check out #50156

@trop trop bot removed the target/41-x-y PR should also be added to the "41-x-y" branch. label Mar 9, 2026
@trop
Copy link
Copy Markdown
Contributor

trop bot commented Mar 9, 2026

I have automatically backported this PR to "38-x-y", please check out #50157

@trop
Copy link
Copy Markdown
Contributor

trop bot commented Mar 9, 2026

I have automatically backported this PR to "40-x-y", please check out #50158

@trop trop bot added in-flight/39-x-y in-flight/38-x-y in-flight/40-x-y and removed target/39-x-y PR should also be added to the "39-x-y" branch. target/38-x-y PR should also be added to the "38-x-y" branch. labels Mar 9, 2026
@trop trop bot added merged/41-x-y PR was merged to the "41-x-y" branch. merged/40-x-y PR was merged to the "40-x-y" branch. merged/39-x-y PR was merged to the "39-x-y" branch. merged/38-x-y PR was merged to the "38-x-y" branch. and removed target/40-x-y PR should also be added to the "40-x-y" branch. in-flight/41-x-y in-flight/40-x-y in-flight/39-x-y in-flight/38-x-y labels Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/38-x-y PR was merged to the "38-x-y" branch. merged/39-x-y PR was merged to the "39-x-y" branch. merged/40-x-y PR was merged to the "40-x-y" branch. merged/41-x-y PR was merged to the "41-x-y" branch. new-pr 🌱 PR opened recently semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants