Skip to content

fix(skills): import fetches only from allowed public sources - #2186

Merged
lilyshen0722 merged 3 commits into
mainfrom
fix/skill-import-fetch-guard
Oct 14, 2026
Merged

lilyshen0722 merged 3 commits into
mainfrom
fix/skill-import-fetch-guard

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

What this changes

POST /api/skills/import and GET /api/skills/requirements fetch a caller-supplied sourceUrl on the backend. The only check before was on the scheme. Both now go through a new guard, fetchTextFromAllowedHost in backend/services/outboundUrlGuard.ts.

Allowed: https on the default port, no credentials in the URL, and a host that exactly matches one of:

  • github.com
  • raw.githubusercontent.com: where toRawGitHubUrl points, and where the contents API's download_urls live
  • api.github.com: the directory walk

Refused: any other host. Before anything resolves it, that includes loopback, RFC 1918, link-local and the metadata host (by address and by name), CGNAT, unspecified, multicast/broadcast, IPv6 ULA and link-local, IPv4-mapped IPv6, other spellings of an IPv4 address, in-cluster service names, and lookalike names. Also refused: non-https schemes, non-default ports, and credentials in the URL.

Redirects are followed by the guard, never by fetch. Every hop is checked against the same host set before it is requested, at most 5. One 15s deadline covers all hops and the body read. The body is read against a cap: 512 KB for a SKILL.md (the largest in the repo is ~66 KB), 1 MB for a contents listing, and the remaining byte budget for directory files.

Route behaviour: a refused URL returns 400 {"error": "Skill source URL must be an https link on github.com or raw.githubusercontent.com."}. The refused host goes to the server log only, capped at 200 characters.

Why an allowlist

The data supports it. 1,657 of the catalog's 1,659 sourceUrls are https://github.com/.../tree/.... The other two are ClawHub page URLs, not SKILL.md files. The frontend's Import button requires pasted content, and the CLI sends no sourceUrl. A non-GitHub sourceUrl sent with pasted content is still stored as metadata and never fetched (parseGitHubSource returns null for it), so those two entries still import that way. A test covers this.

An allowlist doesn't depend on DNS, so it needs no resolve-and-pin step. docs/security-patterns.md now points future outbound fetchers at this module. It also notes that a feature whose destinations can't be listed in advance needs an address-range check, which this module doesn't provide.

Tests

Run on Node 22, the CI pin:

  • backend/__tests__/unit/services/outboundUrlGuard.test.js: 51 tests
    • an allowed host is fetched with redirect: 'manual' and a live signal
    • each refused range is refused with its own reason, and fetch is never called
    • non-https schemes and unparseable input are refused
    • a redirect from an allowed host to a refused destination is refused without being requested
    • an allowed→allowed redirect is followed, including a relative Location
    • five redirects are followed and the sixth is refused
    • body cap boundary
    • a non-2xx final response is returned to the caller
    • the refusal reason is bounded
  • backend/__tests__/unit/routes/skills.import-source-guard.test.js: 12 tests, using the real catalog service and guard with only global fetch spied
    • a refused source on /import returns 400, makes no outbound request and writes nothing
    • a GitHub source that redirects off GitHub returns 400 after exactly one request
    • an off-host download_url in a contents listing is never requested
    • pasted content with a ClawHub sourceUrl imports without a fetch
    • /requirements returns 400 for a refused source
    • positive controls for both routes show the fixture reaches the fetch
  • Existing adjacent suites still pass: skills.requirements, skills.gateway-credentials, admZipRuntimeCompatibility, silentFailure.distinguishable. 78/78 across the six suites.

Mutation check. Ten arms, each landing exactly once at a named line. Every arm goes red, and the suite total stays at 63 in every arm, so no arm passed by failing to compile:

  • guard disabled: 51 red
  • host check removed: 35 red
  • scheme check removed: 8 red
  • redirect hop not re-checked: 7 red
  • redirect: 'follow': 2 red
  • redirect cap off by one: 1 red
  • body cap removed: 1 red
  • reason not bounded: 1 red
  • /import refusal mapped to 500: 7 red

Lint: 0 errors on the three changed .ts files. Every warning is on an existing line. tsc --noEmit -p tsconfig.build.json is clean.

Scope

This PR covers the skill-source fetchers only. No other caller is changed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1

lilyshen0722 and others added 2 commits October 14, 2026 15:18
The skill import and requirements routes fetch a caller-supplied source URL
on the backend. The only check was on the scheme. Both now go through a new
outbound URL guard (backend/services/outboundUrlGuard.ts):

- https only, default port, no credentials in the URL
- the host must exactly match github.com, raw.githubusercontent.com or
  api.github.com. These are the hosts the skill fetchers actually use: 1,657
  of the catalog's 1,659 sourceUrls are github.com.
- redirects are followed by hand and every hop is re-checked; at most 5
- one 15s deadline covers all hops and the body read, plus a body cap
  (512 KB for a SKILL.md, 1 MB for a contents listing)

The contents API's download_url values pass through the same guard. A
refused URL returns 400 with fixed text; the refused host goes to the server
log only, capped at 200 characters. A non-GitHub sourceUrl sent with pasted
content is still stored as metadata and never fetched, so the two ClawHub
catalog entries still import that way.

Tests: guard unit tests (each refused range, including IPv4-mapped IPv6 and
the metadata host, non-https schemes, refused redirects, the redirect cap,
the body cap), plus route tests showing a refused source returns 400 with no
outbound request and no write. A pointer for future outbound fetchers is in
docs/security-patterns.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review at 5c84121 (eng lead, code and security gate).

Checked:

  • services/outboundUrlGuard.ts:
    • https only, on the default port, with no credentials in the URL;
    • an exact-host allowlist;
    • redirects followed by hand (redirect: 'manual'), with every hop re-resolved against the previous URL and re-checked, at most 5;
    • one AbortSignal deadline across all hops and the body read, and a byte cap the caller sets.
  • Both callers use it: import (only when no content is pasted) and requirements. A refusal returns a fixed 400 message; the refused host goes to the server log only.
  • Scope matches the data: the catalog's sources are GitHub; a non-GitHub sourceUrl sent with pasted content is stored as metadata and never fetched; the frontend sends pasted content and the CLI sends no URL. So the allowlist breaks no current path.
  • Tests: at this head, the 6 suites touching skills and the guard pass (73 tests), including the 2 new ones, and lint shows 0 errors on the changed files. The PR's own mutation count (10 of 10 red) is consistent with arms per rule.

Not covered here: the other user-supplied-URL fetchers, which are separate PRs already in progress.

GATE: PASS

The guard now takes a map from each allowed hostname to a constant origin
('github.com' -> 'https://github.com/'). Once a URL passes the checks, the
request is rebuilt as that origin plus the parsed path and query, on the first
request and on every redirect hop. The scheme and host that are fetched are
therefore always a value the caller wrote.

Allowed and refused URLs are unchanged, and all existing tests pass as they
were. A new test maps a host to a different origin and asserts that both the
first request and a redirect hop go to the mapped origin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at 63ad942 (eng lead, code and security gate). This supersedes my PASS at 5c84121, which CodeQL blocked.

Since 5c84121:

  • Constant-origin rebuild: the caller now passes a host-to-origin map (SKILL_SOURCE_ORIGINS: github.com, raw.githubusercontent.com and api.github.com, each mapped to its own https origin with a trailing slash). After the existing checks (https only, no credentials, default port, exact host), every request and every redirect hop is sent to that constant origin plus the parsed path and query. A relative Location still resolves against the parsed URL of the previous hop, then goes through the same check.
  • Test: a new arm checks that the first hop and a redirect both go to the mapped origin.
  • CodeQL: js/request-forgery alert 1812's latest instance on the PR is fixed, not dismissed. No alerts are open on the PR's merge ref, and all checks are green.
  • Tests at this head: the 6 skills and guard suites pass (74 tests), and lint shows 0 errors on the changed files.

Everything else from my 5c84121 review stands: one deadline across hops, the body cap, the fixed 400 message with the refused host logged server-side only, and both import and requirements covered.

GATE: PASS

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 14, 2026
Merged via the queue into main with commit f48bd21 Oct 14, 2026
17 checks passed
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