mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-12 06:06:37 +03:00
security: use JSON.stringify for selector escaping in devtools panel (#93)
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 commit is contained in:
@@ -501,10 +501,10 @@ function renderFindings(findings) {
|
||||
}
|
||||
|
||||
function inspectElement(selector) {
|
||||
const escaped = selector.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
||||
const json = JSON.stringify(selector);
|
||||
chrome.devtools.inspectedWindow.eval(
|
||||
`(function() {
|
||||
var el = document.querySelector('${escaped}');
|
||||
var el = document.querySelector(${json});
|
||||
if (el) { el.scrollIntoView({ behavior: 'smooth', block: 'center' }); inspect(el); }
|
||||
})()`
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user