Skip to content

debug: capture Control API staging 403 response metadata - #50

Merged
zskbot merged 3 commits into
mainfrom
debug/control-api-staging-403-response
Nov 16, 2026
Merged

zskbot merged 3 commits into
mainfrom
debug/control-api-staging-403-response

Conversation

@zskbot

@zskbot zskbot commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

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

  • CI diagnostic only; no runtime, Worker, DNS, secrets, frontend endpoint, or Production changes.
  • Response body is truncated to 360 characters; cookies and authorization headers are never logged.
  • Keep unmerged until diagnostic result is reviewed.

Summary by Sourcery

Capture safe, bounded response metadata when the staging Control API smoke check encounters a non-2xx response.

Enhancements:

  • Add bounded, non-secret metadata to staging Control API smoke-check errors to distinguish edge challenges, redirects, and Worker responses.

CI:

  • Improve CI diagnostics for non-2xx staging API responses by recording sanitized response details, including status, URL, selected headers, and a truncated body.

@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ocodejs-profile Error Error Nov 16, 2026 9:44pm UTC
ocodejs.github.io Ready Ready Preview Nov 16, 2026 9:44pm UTC
pages.ocodejs.theme Ready Ready Preview Nov 16, 2026 9:44pm UTC

Request Review

@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Enrich non-2xx staging smoke-check errors with bounded response metadata to help distinguish edge challenges, redirects, and Worker responses.

  • scripts/check-control-api-staging.mjs L11-25

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-16T21:36:34.021116Z
We couldn’t complete this review. Comment @codex review to try again.
9dba916 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread scripts/check-control-api-staging.mjs Resolved
Comment thread scripts/check-control-api-staging.mjs Resolved
Comment thread scripts/check-control-api-staging.mjs Resolved
Comment thread scripts/check-control-api-staging.mjs Resolved
Comment thread scripts/check-control-api-staging.mjs Resolved
Comment thread scripts/check-control-api-staging.mjs Resolved
Comment thread scripts/check-control-api-staging.mjs Resolved
@vercel

vercel Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Deployment failed for project ocodejs.github.io with the following error:

Resource is limited - try again in 1 day (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/ocodejs-co?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Deployment failed for project pages.ocodejs.theme with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/ocodejs-co?upgradeToPro=build-rate-limit

@zskbot
zskbot merged commit 31e3ca5 into main Nov 16, 2026
4 of 7 checks passed

This branch had an error being deployed

1 failed deployment
Preview – ocodejs-profile — 2269f8be Deployed Nov 16, 2026 by vercel[bot]
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.

1 participant