Repository navigation
Use canonical API host and reject credentialed redirects - #34
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
1 issue found across 6 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/client.ts">
<violation number="1" location="src/client.ts:26">
P2: `redirect: "error"` makes `fetch` throw a generic `TypeError: fetch failed` on any 3xx, and the CLI prints only that message. A user whose `RECOUP_API_URL` redirects will see `Error: fetch failed` with no hint about the cause. Catch the redirect error in a shared helper and rethrow with the URL and the reason.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
|
|
||
| const response = await fetch(url.toString(), { | ||
| method: "GET", | ||
| redirect: "error", |
There was a problem hiding this comment.
P2: redirect: "error" makes fetch throw a generic TypeError: fetch failed on any 3xx, and the CLI prints only that message. A user whose RECOUP_API_URL redirects will see Error: fetch failed with no hint about the cause. Catch the redirect error in a shared helper and rethrow with the URL and the reason.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/client.ts, line 26:
<comment>`redirect: "error"` makes `fetch` throw a generic `TypeError: fetch failed` on any 3xx, and the CLI prints only that message. A user whose `RECOUP_API_URL` redirects will see `Error: fetch failed` with no hint about the cause. Catch the redirect error in a shared helper and rethrow with the URL and the reason.</comment>
<file context>
@@ -23,6 +23,7 @@ export async function get(
const response = await fetch(url.toString(), {
method: "GET",
+ redirect: "error",
headers: {
"x-api-key": getApiKey(),
</file context>
Result
GET and POST now reject redirects before sending a second request, protecting x-api-key and POST bodies from forwarding. The default is https://api.recoupable.dev; RECOUP_API_URL still selects the initial trusted endpoint. Existing PR23 and its broader parity changes are untouched. Open PR33 (6b5f458) separately refactors both verbs into a shared request helper that omits redirect rejection. It is not a prerequisite: future composition must keep non-following redirect handling and explicit 3xx rejection in that helper and retain the native-fetch regression tests. Neither existing PR was modified.
Validation
Local native-fetch tests reproduced 20 redirect failures plus the old-default failure before implementation. All 301/302/303/307/308 GET/POST redirects, both same-origin and cross-origin, now reject with zero destination requests. Direct query/body/key behavior remains intact. Fake credentials and loopback HTTP servers only.
112 tests pass; one candidate-guide check skips unless its path is supplied (passed separately against the Docs companion). TypeScript and build pass. Independent review passed; final-head CI required. The immutable historical guide fixture is unchanged.
Release boundary
Source repair only. No npm publish, installation, credential changes, approved-client replacement or Context identity preflight. Coordinator owns merge. Existing main publish workflow runs automatically on main pushes, so merging is publication-impacting; this PR does not change that workflow. Docs companion pins this source and states publication/installation remain unverified.
Final diagnostic correction: manual non-following fetch rejects 3xx with a fixed safe message, preserves original network failures and existing HTTP/API errors, and exposes no request or redirect details. Independent exact-commit review passed. Docs pins CLI 213de51; final-head CI is distinct from earlier green results.