Skip to content

Security: DOM XSS risk from unescaped plugin template fields in clear_button#1018

Open
tuanaiseo wants to merge 2 commits into
orchidjs:masterfrom
tuanaiseo:contribai/fix/security/dom-xss-risk-from-unescaped-plugin-templ
Open

Security: DOM XSS risk from unescaped plugin template fields in clear_button#1018
tuanaiseo wants to merge 2 commits into
orchidjs:masterfrom
tuanaiseo:contribai/fix/security/dom-xss-risk-from-unescaped-plugin-templ

Conversation

@tuanaiseo
Copy link
Copy Markdown

Problem

The default html renderer builds an HTML string using className, title, role, and tabindex via string interpolation, then parses it with getDom(). If any of these option values are attacker-controlled (for example, passed from untrusted JSON config), attribute injection and script execution are possible.

Severity: high
File: src/plugins/clear_button/plugin.ts

Solution

Avoid string-built HTML for option-driven values. Create elements with document.createElement, assign textContent, and set attributes via setAttribute after strict allowlisting/validation (role enum, numeric tabindex, safe class token pattern). If templating is required, escape all interpolated values.

Changes

  • src/plugins/clear_button/plugin.ts (modified)
  • src/plugins/dropdown_header/plugin.ts (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

…ields

The default `html` renderer builds an HTML string using `className`, `title`, `role`, and `tabindex` via string interpolation, then parses it with `getDom()`. If any of these option values are attacker-controlled (for example, passed from untrusted JSON config), attribute injection and script execution are possible.

Affected files: plugin.ts, plugin.ts

Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com>
…ields

The default `html` renderer builds an HTML string using `className`, `title`, `role`, and `tabindex` via string interpolation, then parses it with `getDom()`. If any of these option values are attacker-controlled (for example, passed from untrusted JSON config), attribute injection and script execution are possible.

Affected files: plugin.ts, plugin.ts

Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com>
html: (data:CBOptions) => {
const div = document.createElement('div');
const className = (data.className || '').split(/\s+/).filter(token => /^[A-Za-z0-9_-]+$/.test(token)).join(' ');
const role = data.role === 'button' ? data.role : 'button';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is every time "button"? When data.role is button, then we use here data.role, otherwise it's hard coded 'button'. It doesn't make sense i think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants