-
Notifications
You must be signed in to change notification settings - Fork 48
AXON-1176: Added base setup to uploading Media #1051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
||
// Fallback: render as HTML for plain text/HTML content | ||
// eslint-disable-next-line react-dom/no-dangerously-set-innerhtml | ||
return <div className={className} style={style} dangerouslySetInnerHTML={{ __html: content || '' }} />; |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium
DOM text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 22 days ago
To fix this vulnerability, contextually encode or sanitize the user-supplied text before passing it to dangerouslySetInnerHTML
in AdfAwareContent.tsx
(line 42). Since in the fallback route the text is not valid ADF and can be any string, we should treat it as plain text by default and ensure that any HTML meta-characters are escaped (e.g., <
becomes <
) unless we know the string is trusted HTML.
The best fix here is to explicitly escape the content before rendering it as HTML, so that any meta-characters are rendered as plain text. Alternatively, a well-known library such as he
(for HTML entity encoding) can be used for escaping. We should update the fallback rendering (line 42) so that content
is escaped before being injected.
Changes/concrete steps:
- In
src/webviews/components/AdfAwareContent.tsx
, import thehe
library (import { escape } from 'he';
). - On line 42, replace
dangerouslySetInnerHTML={{ __html: content || '' }}
withdangerouslySetInnerHTML={{ __html: escape(content || '') }}
. - Ensure that the dependency
he
is available in the project (add to package.json if needed). - No other files need to be changed according to the given snippets.
-
Copy modified line R3 -
Copy modified line R43
@@ -1,5 +1,6 @@ | ||
import { ReactRenderer } from '@atlaskit/renderer'; | ||
import React from 'react'; | ||
import { escape } from 'he'; | ||
|
||
interface AdfAwareContentProps { | ||
content: string; | ||
@@ -39,7 +40,7 @@ | ||
|
||
// Fallback: render as HTML for plain text/HTML content | ||
// eslint-disable-next-line react-dom/no-dangerously-set-innerhtml | ||
return <div className={className} style={style} dangerouslySetInnerHTML={{ __html: content || '' }} />; | ||
return <div className={className} style={style} dangerouslySetInnerHTML={{ __html: escape(content || '') }} />; | ||
}; | ||
|
||
export default AdfAwareContent; |
-
Copy modified lines R1580-R1581
@@ -1577,7 +1577,8 @@ | ||
"turndown": "^7.2.0", | ||
"use-constant": "^2.0.0", | ||
"uuid": "^11.1.0", | ||
"websocket": "^1.0.35" | ||
"websocket": "^1.0.35", | ||
"he": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"@compiled/webpack-loader": "^0.19.6", |
Package | Version | Security advisories |
he (npm) | 1.2.0 | None |
What Is This Change?
How Has This Been Tested?
Basic checks:
npm run lint
npm run test
Advanced checks:
Recommendations: