security: use JSON.stringify for selector escaping in devtools panel#93
Open
xiaolai wants to merge 1 commit intopbakaus:mainfrom
Open
security: use JSON.stringify for selector escaping in devtools panel#93xiaolai wants to merge 1 commit intopbakaus:mainfrom
xiaolai wants to merge 1 commit intopbakaus:mainfrom
Conversation
The inspectElement function previously used manual replace() chains to escape backslashes and single quotes in CSS selectors before passing them to chrome.devtools.inspectedWindow.eval(). This escaping was incomplete: selectors containing crafted sequences of special characters (backticks, newlines, Unicode escapes) could break out of the string literal and inject arbitrary JS into the inspected page context. JSON.stringify produces a properly escaped JS string literal that handles all special characters, eliminating the injection surface entirely.
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.
Summary
replace()escaping withJSON.stringify()in the devtools panel'sinspectElementfunctionchrome.devtools.inspectedWindow.eval()Motivation
The
inspectElementfunction inextension/devtools/panel.jspasses CSS selectors intochrome.devtools.inspectedWindow.eval(). The previous escaping only handled backslashes and single quotes:This is incomplete: selectors containing backticks, newlines, null bytes, or Unicode escape sequences could break out of the single-quoted string literal and inject arbitrary JS into the inspected page's context.
JSON.stringify()produces a properly escaped double-quoted JS string literal that handles all special characters, eliminating the injection surface entirely.Changes
extension/devtools/panel.jsinspectElement(): replace manual escaping withJSON.stringify()Test plan
[data-value="test's"])