Skip to content

security/csp: csp-wildcard fires on host wildcards like https://*.example.com #427

Closed

Description

@nc9

Bug

security/csp warns "CSP script-src allows wildcard (*) / Scripts can load from any domain" for any policy whose script-src has a host wildcard, such as https://*.posthog.com.

In packages/rules/src/security/csp.ts, WEAK_VALUES = ["*", "data:", "blob:", "'unsafe-inline'", "'unsafe-eval'"] is checked with scriptSrc.includes(v). That is a substring match on the whole directive value, so the * in *.posthog.com counts as a bare wildcard.

Expected

Only a bare * source token means "any host". Scheme-only sources (https:, http:, data:, blob:) are the other broad cases. https://*.example.com is scoped to one domain's subdomains and should not trigger csp-wildcard.

Fix

Split the directive value on whitespace and match source tokens exactly. Optionally report scheme-only https: / http: as their own "any host over this scheme" check.

Acceptance

  • script-src 'self' https://*.posthog.com → no csp-wildcard.
  • script-src * → csp-wildcard warn.
  • script-src 'self' https: → broad-scheme warn, if added.
  • Same tokenised matching for the other WEAK_VALUES. data: should not match metadata:-style substrings.

Context: found while checking why security/csp gave identical findings for a broken and a fixed policy (see #425 and #426).

Activity

  1. added
    bug
    P2
    size: XS
    rules
    security
    on Oct 1, 2026
  2. nc9 commented on Oct 1, 2026

    @nc9
    ContributorAuthor

    Fixed in #438 (e4255c0): host wildcards like https://*.example.com no longer fire csp-wildcard; a bare * host still does.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2bugrulessecuritysize: XS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions