Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

2.5 KB
Raw Blame
rules:
    - id: country-flag-polyfill-via-wrapper
      message: |
          `country-flag-emoji-polyfill` imported directly. Import
          `lib/countryFlagEmojiPolyfill` and call `polyfillCountryFlags()` instead.

          The package's second argument is the font URL, and it defaults to
          `https://cdn.jsdelivr.net/npm/[email protected]/dist/TwemojiCountryFlags.woff2`.
          A call site that passes only the family name silently takes that default and
          loads a font from an open CDN. The URL lives inside the dependency, not in our
          source, so searching the repository for the CDN does not find those call sites.

          That matters because the app's `font-src` does not list jsdelivr, and should not.
          An open CDN there serves bytes anyone can publish at a path an attacker picks,
          which is both a wider surface for the browser's font parser and exactly the
          remote origin a CSS-injection exfiltration needs to reach.

          The wrapper holds the family name and the same-origin URL in one place, so the
          policy needs no CDN entry. It also keeps the family name matched to the
          `font-family` our CSS declares for flag glyphs.

          If you genuinely need the package directly, put
          `// nosemgrep: country-flag-polyfill-via-wrapper` on the line before the import
          with a reason, and pass an explicit same-origin URL as the second argument.
      severity: ERROR
      languages: [typescript, javascript]
      paths:
          # The leading slash pins these to the repository root, which is where the app
          # and the wrapper live. Without it semgrep warns that it will anchor them anyway.
          include:
              - /frontend/src
              - /products
              - /common
          exclude:
              # The wrapper is the one place that may import the package.
              - /frontend/src/lib/countryFlagEmojiPolyfill.ts
      pattern-either:
          - pattern: import { ... } from 'country-flag-emoji-polyfill'
          - pattern: import $X from 'country-flag-emoji-polyfill'
          - pattern: import * as $X from 'country-flag-emoji-polyfill'
          - pattern: import 'country-flag-emoji-polyfill'
          - pattern: import('country-flag-emoji-polyfill')
          - pattern: require('country-flag-emoji-polyfill')
      metadata:
          category: security
          confidence: HIGH
          references:
              - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/font-src