Repository navigation
debug: capture Control API staging 403 response metadata - #50
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Reviewer's GuideImplementationEnrich non-2xx staging smoke-check errors with bounded response metadata to help distinguish edge challenges, redirects, and Worker responses.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing |
Codex Review Summary: ❌ FailedThis 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. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Hey - I've found 7 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="scripts/check-control-api-staging.mjs" line_range="12" />
<code_context>
});
- if (!response.ok) throw new Error(path + " returned HTTP " + response.status);
+ if (!response.ok) {
+ const body = (await response.text()).replace(/\\s+/g, " ").slice(0, 360);
+ const location = response.headers.get("location");
+ const safeLocation = location ? (() => { try { const u = new URL(location); return u.origin + u.pathname; } catch { return "present"; } })() : null;
</code_context>
<issue_to_address>
**Sensitive response data reaches CI logs**
When a non-2xx response contains a secret, credential, token, or personal value in its body, `request` includes the response body in the thrown error, and `main().catch` prints that message to CI logs; truncating the body does not redact those values, so they are exposed to CI log readers.
Redact sensitive values or omit the response body from the logged error.
</issue_to_address>
### Comment 2
<location path="scripts/check-control-api-staging.mjs" line_range="18" />
<code_context>
+ throw new Error(JSON.stringify({
+ path,
+ status: response.status,
+ finalUrl: new URL(response.url).origin + new URL(response.url).pathname,
+ server: response.headers.get("server"),
+ cfMitigated: response.headers.get("cf-mitigated"),
</code_context>
<issue_to_address>
**URL paths can expose tokens**
When a non-2xx response or redirect uses a path containing a secret or credential, `finalUrl` and `safeLocation` retain URL pathnames in the error JSON, so a redirect or response URL containing a credential or token in its path is written to CI logs despite the query string being omitted.
Omit URL pathnames or redact sensitive path segments before including these URLs in the diagnostic.
Also at `scripts/check-control-api-staging.mjs:22`.
</issue_to_address>
### Comment 3
<location path="scripts/check-control-api-staging.mjs" line_range="12" />
<code_context>
});
- if (!response.ok) throw new Error(path + " returned HTTP " + response.status);
+ if (!response.ok) {
+ const body = (await response.text()).replace(/\\s+/g, " ").slice(0, 360);
+ const location = response.headers.get("location");
+ const safeLocation = location ? (() => { try { const u = new URL(location); return u.origin + u.pathname; } catch { return "present"; } })() : null;
</code_context>
<issue_to_address>
**Large error bodies exhaust resources**
When the staging or edge endpoint returns a very large or unending non-2xx body, `response.text()` buffers the entire body before `.slice(0, 360)` runs, so the staging check can consume excessive memory or time instead of reporting bounded diagnostics.
Read and retain only a bounded amount of the response body before building the diagnostic.
</issue_to_address>
### Comment 4
<location path="scripts/check-control-api-staging.mjs" line_range="12" />
<code_context>
});
- if (!response.ok) throw new Error(path + " returned HTTP " + response.status);
+ if (!response.ok) {
+ const body = (await response.text()).replace(/\\s+/g, " ").slice(0, 360);
+ const location = response.headers.get("location");
+ const safeLocation = location ? (() => { try { const u = new URL(location); return u.origin + u.pathname; } catch { return "present"; } })() : null;
</code_context>
<issue_to_address>
**Body read failures hide response diagnostics**
When a non-2xx response body stalls, times out, or errors before reaching EOF, `response.text()` rejects before the status and headers are added to the error, so the outer catch reports only the body-read or abort error and the intended response diagnostics are lost.
Preserve the status and headers in the diagnostic when reading the body fails.
</issue_to_address>
### Comment 5
<location path="scripts/check-control-api-staging.mjs" line_range="11" />
<code_context>
...init
});
- if (!response.ok) throw new Error(path + " returned HTTP " + response.status);
+ if (!response.ok) {
+ const body = (await response.text()).replace(/\\s+/g, " ").slice(0, 360);
+ const location = response.headers.get("location");
</code_context>
<issue_to_address>
**Preflight failures omit response diagnostics**
When the CORS preflight receives a non-204 response, `main()` handles the OPTIONS response separately from `request()` and throws a fixed CORS error, so the response status and metadata are omitted and CI cannot distinguish an edge challenge from a CORS or Worker rejection.
Include the preflight response status and metadata in the error diagnostics.
</issue_to_address>
### Comment 6
<location path="scripts/check-control-api-staging.mjs" line_range="12" />
<code_context>
});
- if (!response.ok) throw new Error(path + " returned HTTP " + response.status);
+ if (!response.ok) {
+ const body = (await response.text()).replace(/\\s+/g, " ").slice(0, 360);
+ const location = response.headers.get("location");
+ const safeLocation = location ? (() => { try { const u = new URL(location); return u.origin + u.pathname; } catch { return "present"; } })() : null;
</code_context>
<issue_to_address>
**Whitespace obscures useful error text**
When a non-2xx response body contains substantial whitespace before useful diagnostic details, `/\\s+/g` matches literal backslash-and-s sequences rather than whitespace, so whitespace can consume the 360-character excerpt and leave useful response details out of the CI diagnostic.
Use a whitespace-matching regular expression to collapse whitespace before truncating the body.
</issue_to_address>
### Comment 7
<location path="scripts/check-control-api-staging.mjs" line_range="14" />
<code_context>
+ if (!response.ok) {
+ const body = (await response.text()).replace(/\\s+/g, " ").slice(0, 360);
+ const location = response.headers.get("location");
+ const safeLocation = location ? (() => { try { const u = new URL(location); return u.origin + u.pathname; } catch { return "present"; } })() : null;
+ throw new Error(JSON.stringify({
+ path,
</code_context>
<issue_to_address>
**Relative redirect targets are hidden**
When a non-2xx response has a relative `Location` header, `new URL(location)` rejects the relative value, and the catch replaces it with `"present"`, so the diagnostic omits the redirect target path.
Resolve the `Location` value against the response URL before formatting it.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 7 findings to address first, and on a failed request, the thrown error now includes up to 360 characters of the response body, which may be retained in the script runner’s logs after the failure. The exposure is bounded and log retention can be managed, but reverting would not erase output already recorded.
Blocking findings: scripts/check-control-api-staging.mjs:12, scripts/check-control-api-staging.mjs:18, scripts/check-control-api-staging.mjs:12, scripts/check-control-api-staging.mjs:12, scripts/check-control-api-staging.mjs:11, and 2 more
|
Deployment failed for project ocodejs.github.io with the following error: Learn More: https://vercel.com/ocodejs-co?upgradeToPro=build-rate-limit |
|
Deployment failed for project pages.ocodejs.theme with the following error: Learn More: https://vercel.com/ocodejs-co?upgradeToPro=build-rate-limit |
Purpose
Capture bounded, non-secret HTTP response metadata when the staging API smoke check receives a non-2xx response. This identifies whether the 403 is an edge challenge, redirect, or Worker response.
Safety
Summary by Sourcery
Capture safe, bounded response metadata when the staging Control API smoke check encounters a non-2xx response.
Enhancements:
CI: