[DevTools] Fix XSS in standalone onError via innerHTML#36431
[DevTools] Fix XSS in standalone onError via innerHTML#36431tomohiro86 wants to merge 1 commit intofacebook:mainfrom
Conversation
Use textContent instead of template literal interpolation when rendering error messages in the standalone DevTools shell to prevent potential XSS from unescaped error message strings.
|
Hi @tomohiro86! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
In
packages/react-devtools-core/src/standalone.js, theonErrorfunction was interpolating a server errormessagestring directly into aninnerHTMLtemplate literal:If the
messagestring contained HTML (e.g.<img src=x onerror="...">) it would be parsed and executed by the browser.This PR fixes it by setting the static HTML structure first, then assigning the message via
textContent, which the browser treats as plain text and never interprets as markup.The
messagevalue comes from Node.jshttp.Server/net.Servererror events (server.on('error', ...)). These are normally OS/network-level error strings and not directly attacker-controlled, so real-world exploitability is limited. Nevertheless the code structure allowed HTML injection and the fix is straightforward.How did you test this change?
Manually verified that a normal server error (e.g.
EACCES) still renders the error message as plain text in the standalone DevTools shell. No automated tests exist for this UI path inreact-devtools-core.