Skip to content

backfill-images.ts: anchor GitHub token fallback to exact hostname (twin of #1931 fix) #1968

Description

@jung-thomas

Follow-up from #1967 (attachment object-store pipeline).

scripts/backfill-images.ts:68 gates the GitHub Bearer-token fallback on an UNANCHORED substring regex: /raw\.githubusercontent\.com/.test(u). A lookalike host such as https://raw.githubusercontent.com.evil.com/x (or https://evil.com/?q=raw.githubusercontent.com) matches, so the GitHub token could be sent to an attacker-controlled host (credential exfiltration). Low exploitability in practice (the collected URLs originate from sap-tutorials-org tutorial HTML), but the pattern is wrong.

The attachment sibling scripts/backfill-attachments.ts already fixed this in #1967 with an exact-hostname helper:

export function isRawGithubHost(u: string): boolean {
  try { return new URL(u).hostname.toLowerCase() === 'raw.githubusercontent.com'; } catch { return false; }
}

Port isRawGithubHost into backfill-images.ts (or share it), replace the substring test at line 68, and add the same unit tests (true for the legit host; false for subdomain lookalike, query-param embed, malformed URL).

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions