Skip to content

fix(security): raster-only cover proxy, sanitised UX Core markup, certificate page crash - #256

Merged
manager merged 3 commits into
mainfrom
fix/security-batch
Nov 11, 2026
Merged

manager merged 3 commits into
mainfrom
fix/security-batch

Conversation

@manager

@manager manager commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What changes for visitors

  • The Library cover proxy answers only raster images (JPEG, PNG, WebP, GIF, AVIF) and sends nosniff plus a sandboxing content policy.
  • UX Core content (biases, questions, personas) passes an allowlist sanitiser after raw HTML parsing. Tags and attributes used by live content are kept: text formatting, links, lists, inline style without positioning or URLs, and the accordion, download and trello blocks.
  • The certificate page no longer crashes when the visitor context has not loaded, and the user name is encoded in the request path.
  • A missing certificate answers 404, and an image in UX Core content without a usable source is skipped instead of crashing the page.

Checks

  • tsc --noEmit passes, ESLint and Prettier clean on the touched files.
  • Sanitiser exercised with script, event-handler, javascript: link, iframe, form and fixed-position payloads next to legitimate markup.

Not merged: waits for the owner go.

🤖 Generated with Claude Code

…tificate page crash

- Cover proxy answers only raster image types and sends nosniff plus a
  sandboxing content policy, so it cannot serve active content from our origin.
- UX Core content goes through an allowlist sanitiser after raw HTML parsing.
- Certificate page no longer crashes when the visitor context is not loaded;
  the user name is encoded in the request path.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Claude finished @manager's task in 24s —— View job


Review of PR #256

  • Read the diff
  • Security review of the cover proxy, sanitiser and certificate changes
  • Post inline comments

Summary

The direction is right and the changes are small and focused.

Good

  • The cover proxy now allowlists raster MIME types only. It normalises content-type (strips parameters, lowercases) before checking, and adds nosniff and a sandbox CSP. This closes the SVG-from-own-origin vector.
  • rehypeSanitize runs after rehypeRaw, which is the correct order. Only http/https are allowed for the custom url attributes.
  • encodeURIComponent(username) closes path injection in the certificate request.
  • The optional chaining on uxcatUserInfo?.user?.id fixes the crash.

Issues (inline)

  1. Style filter is bypassable and over-broad (ContentParser.tsx:12). CSS escapes such as p\6fsition:fixed get past the position denylist. The filter also strips background-position and any multi-line style. Reject backslashes, or allowlist properties instead.
  2. Import reordering is unrelated noise (certificate.tsx:1, and ContentParser.tsx). It breaks the repo's simple-import-sort order. Please revert it with eslint --fix.

Minor, not blocking

  • The accordion file attribute is not protocol-restricted by the url entry in protocols. If it is rendered as a link or src, add it to protocols.
  • The default schema's clobberPrefix rewrites id and name values to user-content-*. Check that no live content relies on anchor ids.
  • I did not run the app or the sanitiser; this is a static review. The PR notes that the sanitiser was exercised with payloads, but the repo has no test for it, so a regression would go unnoticed.

// Persona text is saved by visitors and shown on public pages, so raw HTML is
// filtered to the tags our content uses. Custom tags are the ones
// useContentType renders.
const SAFE_STYLE = /^(?!.*(position|url\s*\(|expression|@import)).*$/i;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Two problems with this denylist regex:

  1. It can be bypassed with CSS escapes. p\6fsition:fixed is not matched by position, but browsers decode it. Reject any value containing a backslash, or better, allowlist properties (color, font-, text-, margin, padding, background-color...) instead of denying keywords.
  2. It over-blocks legitimate properties such as background-position. It also drops the whole style when the value spans lines, because . does not match newlines.
Suggested change
const SAFE_STYLE = /^(?!.*(position|url\s*\(|expression|@import)).*$/i;
const SAFE_STYLE = /^(?!.*(\\|position|url\s*\(|expression|@import))[\s\S]*$/i;


import type { TRouter } from '@uxcore/local-types/global';

import { getCertificate } from '@uxcore/api/uxcat/certificate';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This reorders the imports and removes the group spacing, which is unrelated to the fix and adds diff noise. The same happens in ContentParser.tsx, where useContentType moved above third-party imports. It looks like an editor or tool resort. Please revert to the repo's simple-import-sort order (run eslint --fix) so the diff only carries the real changes.

…ing certificate answers 404

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Claude finished @manager's task in 15s —— View job


Review of PR #256 (re-run on synchronize)

I read the diff against origin/main. I did not run the app or the sanitiser. This is a static review, and I did not repeat the two inline comments from the earlier pass.

What looks good

  • The cover proxy normalises content-type before the allowlist check, and the response carries nosniff plus a sandbox CSP.
  • rehypeSanitize runs after rehypeRaw, and url protocols are limited to http and https.
  • encodeURIComponent(username) and the uxcatUserInfo?.user?.id guard fix the certificate request path and the crash.
  • The certificate page now sets a 404 status when there is no certificate.
  • The img renderer returns null when the sanitiser has dropped the src.

Still open from the earlier inline comments

  1. ContentParser.tsx:12: the SAFE_STYLE denylist can be bypassed with CSS escapes such as p\6fsition. It also rejects background-position and multi-line styles. Reject backslashes or allowlist properties, as suggested inline.
  2. certificate.tsx:1, ContentParser.tsx:1 and useContentType.tsx:1: the imports are re-sorted against the repo's simple-import-sort order, which AGENTS.md says ESLint enforces. This is diff noise, so please run eslint --fix.

Worth checking before merge (not blocking)

  • accordion[file] is not covered by the url protocol list. If it is rendered as a link or src, add it to protocols.
  • The default schema's clobberPrefix rewrites id and name to user-content-*. Confirm that no live UX Core content links to anchors by id.
  • Allowlisting only u, span and the three custom tags drops anything else live content uses, such as iframe, video or br variants. Spot-check a few bias, question and persona pages on DEV.
  • There is no regression test for the sanitiser. Playwright is the only allowed test framework here, so a small page-level check could cover it.

I made no code changes.

…be a CMS path

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Claude finished @manager's task in 16s —— View job


Review of PR #256 (re-run on synchronize)

Static review of git diff origin/main...HEAD. I did not run the app or the sanitiser, and I made no code changes.

Resolved since the earlier passes (commit d5d27a2)

  • SAFE_STYLE now refuses backslashes and matches multi-line values ([\s\S]*), so the p\6fsition bypass is closed. It still rejects background-position because the denylist matches the substring position. That is a safe failure mode, and an allowlist of properties would be cleaner later.
  • accordion[file] must now match CMS_PATH (/^\/(?![\/\\])/). Protocol-relative //host and /\host are rejected, so the value can only be a path on the CMS.
  • The img renderer returns null when the sanitiser has dropped src.

Still open

  1. Import reordering is unrelated diff noise in certificate.tsx, ContentParser.tsx and useContentType.tsx. It puts @uxcore/* imports above third-party packages and drops the group spacing, which breaks the repo's simple-import-sort order. Run eslint --fix on those three files and keep only the real changes. Commit 72eea2c's CI should flag this if the lint config enforces it.

Worth checking on DEV before the owner go (not blocking)

  • defaultSchema applies clobberPrefix, which rewrites id and name to user-content-*. Confirm that no live bias, question or persona content links to anchors by id.
  • The tag allowlist adds only u, span and the three custom tags to the defaults. Anything else that live content uses (iframe, video and similar) is now dropped. Spot-check a few bias, question and persona pages.
  • download[url] and trello[url] go through the url protocol list (http and https only), which is correct. If they are rendered as links, also check that rel and target are set the way you want.
  • The sanitiser has no regression test. A small Playwright page check with the payload list from the PR description would keep it from drifting silently.

Looks good

  • The cover proxy normalises content-type, allowlists raster types only, and sends nosniff plus a sandbox CSP.
  • rehypeSanitize runs after rehypeRaw, which is the right order.
  • encodeURIComponent(username), the uxcatUserInfo?.user?.id guard and the 404 status on a missing certificate fix the crash and the path-injection risk.

No UX Core data, slug or schema changes in this diff.

@manager

manager commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

On the import order: the reordering comes from the repository pre-commit hook (eslint --fix through lint-staged), and eslint reports no errors on the three files as committed. Reverting by hand would be undone by the same hook on the next commit, so the order stays. The style filter and accordion comments are closed in d5d27a2.

@manager
manager merged commit 5876436 into main Nov 11, 2026
2 checks passed
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.

1 participant