Repository navigation
refactor: pass the CKAN settings to safe-http.ts per call - #594
Merged
aborruso merged 1 commit intoNov 12, 2026
Merged
Conversation
safe-http.ts no longer reads process.env. http.ts reads the CKAN_* settings at the same moments as before and passes them explicitly: validateServerUrl and assertRedirectKeepsPrivateExemption take a UrlGuardSettings object (lists plus the setting names shown in messages); safeFetch takes a function returning it, called at each redirect hop as before; isPrivateHostAllowed takes the list; decodePossiblyCompressed takes the decompression cap (read once at load, as before); createSsrfSafeLookup keeps the caller's settings object and takes a privateHosts getter, read at each lookup because the agents are kept for the process. No module-level configuration in safe-http.ts. http.ts exports wrappers under the same 20 names and types, so no importer and no test changes; messages are byte-identical. The two startup checks (warnIfPrivateHostsOverHttp, assertHttpAllowlistConfigured), which only read CKAN_* settings, move verbatim to http.ts, and so does the cache of the safe agents (createSafeAgents in safe-http.ts builds them). CKAN and sparql_query mentions in safe-http.ts comments move to http.ts or become generic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
[Medium impact] This PR appears safe to merge; no actionable issues were found.
|
aborruso
approved these changes
Nov 12, 2026
aborruso
left a comment
Member
There was a problem hiding this comment.
Thanks Björn, this is what we agreed in #590, and it stays within that scope.
Checked against the base (205ba4a):
utils/http.tsexports the same 20 names before and after; nothing else importssafe-http.ts.safe-http.tshas noprocess.envand no CKAN mention left. Settings are passed per call, with no module-level state. The size caps are read at load, the rest on every call, redirect hop and lookup, as before.- The defaults fail closed:
createSsrfSafeLookupwithout a private-host getter gets an empty list, andsafeFetchrequiresurlGuard. - Messages are unchanged, and the two startup checks moved verbatim.
- It merges cleanly with
main(#593 touched one hint line inhttp.ts). npm run build,npm run build:workerandnpm test(726 passed, 6 skipped) are green locally.
One nit, not blocking: const raw = privateHosts; in isPrivateHostAllowed is now redundant.
The missing test for CKAN_PRIVATE_HOSTS reaching the axios lookup can come separately if you feel like it; as you say, it fails closed.
aborruso
added a commit
that referenced
this pull request
Nov 12, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RCCNPJK12mLzKydJ8Cp5Lc
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.
Step 2 as agreed in #590, and the last one:
safe-http.tsno longer reads any configuration or names CKAN.What changes.
http.tsreads theCKAN_*settings exactly as before (the two size caps once at load, the others on every call) and passes them explicitly. There is no module-level configuration insafe-http.ts.validateServerUrlandassertRedirectKeepsPrivateExemptiontake aUrlGuardSettingsobject: the allowlist and the private hosts as the raw comma-separated strings, plus the two setting names that the messages show.safeFetchtakes a function that returns that object. It is called at each redirect hop, which is when the settings are read today.isPrivateHostAllowedtakes the list, anddecodePossiblyCompressedtakes the decompression cap.createSsrfSafeLookupkeeps the caller's settings object, as today, and takes aprivateHostsgetter. The getter is called at each lookup, because the agents are kept for the process and the list is read at lookup time today.http.tsexports thin wrappers under the same names. Every export ofutils/http.jsis unchanged in name and type (20), so no importer and no test changes.safe-http.tstohttp.ts:warnIfPrivateHostsOverHttpandassertHttpAllowlistConfigured. They are startup checks that only readCKAN_*settings and print CKAN text.http.ts.safe-http.tskeeps the builder,createSafeAgents.safe-http.tsthat named CKAN orsparql_querynow say the same thing generically, or the text moved to the wrapper inhttp.ts.One gap I noticed and left alone, since this step changes no tests: no test checks that
CKAN_PRIVATE_HOSTSreaches the axios agents' lookup for a listed host name. The existing agent tests start on127.0.0.1, where Node skips the lookup. The gap is the same onmain, and a regression there would fail closed. A small test for it can come later if you want one.How to check.
git diff main -- src/utils/safe-http.ts | grep -i ckanshows only removed lines.npm test: 726 passed, 6 skipped, as onmain; no test file touched.CKAN_ALLOWED_DOMAINSwhile asafeFetchredirect is pending, or the settings object of a lookup after creating it, gives the same result as onmain. I checked this with a throwaway script against both commits; it is not added as a test.npm run smoke: 18/18 against the live portals (2026-11-12);tests/smoke/cases.jsonuntouched.npm run buildandnpm run build:workersucceed. The Worker bundle grows by 0.4 KB, the wrappers.src/utils/http.tsare identical before and after, in names and types, compared with the TypeScript checker. Onsrc/utils/andsrc/transport/http.ts, the checker gives the same four errors as onmain.AI assistance: prepared with Claude (Anthropic) under my direction and review, with automated reviews before opening.
🤖 Generated with Claude Code