Skip to content

feat: per-origin object policies for mixin security options#162

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/extend-crossoriginmixins-option
Draft

feat: per-origin object policies for mixin security options#162
Copilot wants to merge 3 commits intomainfrom
copilot/extend-crossoriginmixins-option

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

The four mixin security options (allowExternalMixins, allowLocalMixinScripts, allowSameOriginMixinScripts, allowCrossOriginMixinScripts) only accepted a single string policy applied globally. This made it impossible to trust specific cross-origin sources differently — e.g., allow scripts from one CDN while blocking another.

Changes

  • src/lib/mixin.js — Added resolvePolicy(option, origin, fallback) helper and getUrlOrigin() utility. Both the fetch-policy and script-execution-policy checks now call resolvePolicy, which passes string values through unchanged and resolves object values by exact origin key → '*' wildcard → 'block' default. Updated error messages to mention the object form.

  • test/mixin_types.tests.js — Six new tests in a "per-origin policy objects" suite covering: origin-specific allow, wildcard block, wildcard allow, empty-object default-to-block, and object-form script policies (allow and noscript).

  • Docsmixin_types.md updated with "Object form" subsections and examples; error_codes.md fix guidance updated; WRITING_TESTS.md option table updated.

Usage

new SmarkForm(el, {
  allowExternalMixins: {
    'https://trusted-cdn.example.com': 'allow',
    '*': 'block',
  },
  allowCrossOriginMixinScripts: {
    'https://trusted-cdn.example.com': 'allow',
    'https://partial-trust.example.com': 'noscript',
    '*': 'block',
  },
});

Keys are origin strings; '*' is the wildcard fallback; missing key and no '*' defaults to 'block'. String values continue to work exactly as before.

…cies

Add `resolvePolicy(option, origin, fallback)` helper to `src/lib/mixin.js`
that allows `allowExternalMixins`, `allowLocalMixinScripts`,
`allowSameOriginMixinScripts`, and `allowCrossOriginMixinScripts` to accept
either the existing string values or a per-origin object map.

Object form keys are origin strings (e.g. 'https://cdn.example.com');
the special '*' key acts as a wildcard fallback, defaulting to 'block' when
absent. This enables fine-grained trust policies such as:

  allowCrossOriginMixinScripts: {
    'https://trusted-cdn.example.com': 'allow',
    '*': 'block',
  }

- Add `getUrlOrigin(absoluteUrl)` helper used by both policy checks
- Update fetch-policy check to use `resolvePolicy` with origin lookup
- Update script-policy check to use `resolvePolicy` for all origin classes
- Update error messages to mention the per-origin object form
- Add 6 new Playwright tests covering object-form policies
- Update mixin_types.md with object-form API docs and examples
- Update error_codes.md fix guidance to mention per-origin objects
- Update WRITING_TESTS.md option table to document object form

Agent-Logs-Url: https://github.com/bitifet/SmarkForm/sessions/e2eab886-2944-4758-a7b2-bcd972700800

Co-authored-by: bitifet <1643647+bitifet@users.noreply.github.com>
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