Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"immutable": "^3.8.3",
"js-yaml": "^4.1.1",
"lodash": "^4.18.1",
"marked": "14.0.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-i18next": "11.18.6",
Expand Down
11 changes: 9 additions & 2 deletions src/clipboard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
export const copyToClipboard = (value: string): void => {
import { marked } from 'marked';

export const copyToClipboard = async (value: string): Promise<void> => {
try {
navigator.clipboard.writeText(value);
const html = marked.parse(value) as string;
const clipboardItem = new ClipboardItem({
'text/plain': new Blob([value], { type: 'text/plain' }),
'text/html': new Blob([html], { type: 'text/html' }),
});
await navigator.clipboard.write([clipboardItem]);
Comment on lines +5 to +10
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

find . -type f -name "clipboard.ts" | head -20

Repository: openshift/lightspeed-console

Length of output: 91


🏁 Script executed:

cat -n ./src/clipboard.ts

Repository: openshift/lightspeed-console

Length of output: 696


🏁 Script executed:

# Check for marked configuration and sanitization
rg "marked\." --type ts --type js | head -20

Repository: openshift/lightspeed-console

Length of output: 137


🏁 Script executed:

# Check package.json for marked version and dependencies
cat -n package.json | grep -A 20 "marked"

Repository: openshift/lightspeed-console

Length of output: 826


🏁 Script executed:

# Check if DOMPurify or other sanitization libraries are used
rg "DOMPurify|sanitize" --type ts --type js

Repository: openshift/lightspeed-console

Length of output: 54


🏁 Script executed:

# Check if there are other clipboard-related utilities or tests that might show the expected behavior
rg "copyToClipboard\|clipboard" --type ts --type js -l

Repository: openshift/lightspeed-console

Length of output: 54


🌐 Web query:

marked 14.0.0 sanitization HTML security

💡 Result:

In marked version 14.0.0, there is no built-in HTML sanitization feature. The legacy 'sanitize' and 'sanitizer' options were removed in version 8.0.0. Marked explicitly warns that it does not sanitize output HTML and users must apply a separate sanitization library to prevent XSS attacks when processing untrusted input. Key security guidance from official documentation: - Marked converts Markdown (including raw HTML blocks) to HTML without filtering dangerous content like script tags or malicious attributes. - Recommended approach: Parse with marked first, then sanitize the resulting HTML. - Primary recommendation: Use DOMPurify.sanitize(marked.parse(markdown)). - Alternatives: sanitize-html, insane, or js-xss. Example for secure usage: import { marked } from 'marked'; import DOMPurify from 'dompurify'; const safeHtml = DOMPurify.sanitize(marked.parse(userMarkdown)); Using extensions with hooks.postprocess: marked.use({ hooks: { postprocess(html) { return DOMPurify.sanitize(html); } } }); No XSS vulnerabilities are reported specifically for marked 14.0.0 in security databases like Snyk or GitHub Advisories. Past issues (pre-v4) involved ReDoS, fixed long ago. Version 14.0.0 (released Aug 2024) focuses on renderer changes, with no sanitization-related updates. For untrusted user input, always sanitize post-parsing to mitigate risks from raw HTML in Markdown.

Citations:


🏁 Script executed:

# Check if marked has a sanitizer option or if there's any config
rg "new marked\|marked\.setOptions\|marked\.defaults" --type ts --type js

Repository: openshift/lightspeed-console

Length of output: 54


Sanitize the HTML and add a fallback for older browsers.

marked.parse(value) preserves raw HTML from the markdown source, and marked 14.0.0 has no built-in sanitization. The text/html clipboard payload can carry untrusted markup into downstream paste targets without external sanitization. Additionally, this implementation unconditionally depends on ClipboardItem/navigator.clipboard.write(), so browsers without support for the richer clipboard API will silently fail instead of falling back to navigator.clipboard.writeText(value).

Recommendations:

  • Sanitize the generated HTML before placing it on the clipboard (use DOMPurify or similar)
  • Add a fallback branch for browsers without ClipboardItem support
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/clipboard.ts` around lines 5 - 10, marked.parse(value) currently emits
unsanitized HTML and you unconditionally use
ClipboardItem/navigator.clipboard.write which will fail in older browsers; fix
by sanitizing the HTML output (e.g., call DOMPurify.sanitize(html) on the result
of marked.parse(value)) and then use ClipboardItem and navigator.clipboard.write
only when both ClipboardItem and navigator.clipboard.write are available,
otherwise fall back to navigator.clipboard.writeText(value); update references
inside this block (marked.parse, the html variable, ClipboardItem,
navigator.clipboard.write, navigator.clipboard.writeText) to use the sanitized
HTML and the fallback branch.

} catch (err) {
// eslint-disable-next-line no-console
console.error('Failed to copy to clipboard: ', err);
Expand Down