Repository navigation
fix(skills): import fetches only from allowed public sources - #2186
Merged
Merged
Conversation
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
…mple Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1
lilyshen0722
commented
Oct 14, 2026
lilyshen0722
left a comment
Contributor
Author
There was a problem hiding this comment.
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
AbortSignaldeadline across all hops and the body read, and a byte cap the caller sets.
- Both callers use it:
import(only when nocontentis pasted) andrequirements. 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
sourceUrlsent 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
commented
Oct 14, 2026
lilyshen0722
left a comment
Contributor
Author
There was a problem hiding this comment.
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 relativeLocationstill 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-forgeryalert 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
POST /api/skills/importandGET /api/skills/requirementsfetch a caller-suppliedsourceUrlon the backend. The only check before was on the scheme. Both now go through a new guard,fetchTextFromAllowedHostinbackend/services/outboundUrlGuard.ts.Allowed: https on the default port, no credentials in the URL, and a host that exactly matches one of:
github.comraw.githubusercontent.com: wheretoRawGitHubUrlpoints, and where the contents API'sdownload_urls liveapi.github.com: the directory walkRefused: 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 arehttps://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 nosourceUrl. A non-GitHubsourceUrlsent with pasted content is still stored as metadata and never fetched (parseGitHubSourcereturns 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.mdnow 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 testsredirect: 'manual'and a live signalfetchis never calledLocationbackend/__tests__/unit/routes/skills.import-source-guard.test.js: 12 tests, using the real catalog service and guard with only globalfetchspied/importreturns 400, makes no outbound request and writes nothingdownload_urlin a contents listing is never requestedsourceUrlimports without a fetch/requirementsreturns 400 for a refused sourceskills.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:
redirect: 'follow': 2 red/importrefusal mapped to 500: 7 redLint: 0 errors on the three changed
.tsfiles. Every warning is on an existing line.tsc --noEmit -p tsconfig.build.jsonis 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