security: slug-validate field_name on write to close fieldId XSS sink

Open
#1,031 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
40/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
typescript
Domain
frontend, security

Research direction

Start in packages/core/src/templates/components/dynamic-field.template.ts, where fieldId and fieldName are interpolated into the id, name and onclick attributes, and look at the removeMediaFromMultiple call and the escapeJsAttr helper. Find where field_name is written to the schema or field definitions, since the issue asks for validation there. Done means field names outside [a-z0-9_-] are rejected on write and the template tests still pass. The issue does not say how to handle existing stored names, so check with maintainers before deciding that.

Written by the indexing model from the issue text.

Description

area: admin bug priority: P1 security triage: needs-validation

Summary

In dynamic-field.template.ts, the onclick for multi-media remove is:

onclick="removeMediaFromMultiple('${fieldId}', '${escapeJsAttr(url)')"

fieldId derives from field.name and is interpolated without escaping. A crafted field name containing ' or " can break the JS string context → stored XSS via the schema/field-definition path.

Root fix

Slug-validate field_name on write (allow only [a-z0-9_-]). This closes the sink for all similar id/name-from-field_name sinks in the template, not just this one.

Scope

Explicitly scoped out of #1029 (which fixed the media value/url sinks). Pre-existing issue, not introduced by that PR.

Related

  • #1028 — stored XSS via media field value (fixed in #1029)
  • packages/core/src/templates/components/dynamic-field.template.ts — fieldId/fieldName interpolated into id, name, onclick attrs throughout
Dominant language
TypeScript
Stars
1.8k
Forks
219
Avg merge
2d 21h
Merged PRs (30d)
67

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SonicJs-Org/sonicjs

All issues in SonicJs-Org/sonicjs

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.