Skip to content

#6339 Improve message content isolation - #6340

Open
martgil wants to merge 5 commits into
masterfrom
issue-6339-harden-css-sanitizer
Open

martgil wants to merge 5 commits into
masterfrom
issue-6339-harden-css-sanitizer

Conversation

@martgil

@martgil martgil commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

This PR removes negative margins in both CSS sanitizers so untrusted message content cannot be displaced over trust UI.

close #6339


Tests (delete all except exactly one):

  • Tests added or updated

To be filled by reviewers

I have reviewed that this PR... (tick whichever items you personally focused on during this review):

  • addresses the issue it closes (if any)
  • code is readable and understandable
  • is accompanied with tests, or tests are not needed
  • is free of vulnerabilities
  • if this PR fixes a security issue: I tried to bypass the new fix, and failed (leave unticked if this PR is not a security fix)
  • is documented clearly and usefully, or doesn't need documentation

Allowlisted negative margins let untrusted message content escape its
container and repaint trust UI. Both CSS sanitizers now remove margin
declarations with negative lengths, with regression tests for shorthand,
calc(), !important and logical-property variants.
@martgil
martgil requested a review from sosnovsky as a code owner November 18, 2026 07:37
Strip var()/attr()/env() margins and positioning offsets, and stop
stripping valid positive calc() margins. Extends regression tests with
the bypass variants found in review.
@martgil

martgil commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Hi @sosnovsky - This one is ready for a review. Thank you!

Comment thread extension/js/common/platform/xss.ts Outdated
Comment on lines +149 to +150
private static readonly NEGATIVE_CSS_LENGTH = /(?:^|\s|\()-(?:\d|\.)/;
private static readonly CSS_FUNCTION_VALUE = /\b(?:var|attr|env)\(/i;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

these regexes allow calc expression, which can produce negative margins. for example, margin-top: calc(1% - 200px); will probably pass our check while giving negative margin. we should handle such cases too

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.

Improve message content isolation

2 participants