Skip to content

fix(responses): reject function-based API keys in WebSocket constructors - #2586

Merged
HAYDEN-OAI merged 7 commits into
openai:mainfrom
sylvesterkaczmarek:fix/responses-ws-function-api-key
Sep 16, 2026
Merged

HAYDEN-OAI merged 7 commits into
openai:mainfrom
sylvesterkaczmarek:fix/responses-ws-function-api-key

Conversation

@sylvesterkaczmarek

@sylvesterkaczmarek sylvesterkaczmarek commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Responses WebSocket authentication is synchronous, so a client with an unresolved function-based apiKey cannot authenticate the socket. At the same time, a function-backed client that has already run _callApiKey() has a resolved string in client.apiKey and should remain usable.

The current fix enforces that invariant at the shared stable and beta ResponsesWSBase._authHeaders() boundary instead of only in the concrete Node constructors:

  • if client.apiKey is a resolved string, use it for the Authorization header regardless of whether the original client option was a function;
  • if no resolved key exists, fail before opening a WebSocket rather than silently performing an unauthenticated handshake;
  • because the guard lives in the published base classes, custom transport subclasses cannot bypass it.

Review follow-up

This addresses both review findings on the original head:

  1. already-resolved function credentials are accepted;
  2. unresolved credentials are rejected at the shared authentication boundary, covering stable, beta, and custom ResponsesWSBase subclasses.

Tests

Stable and beta regression coverage verifies both states:

  • an unresolved function-backed client throws before a socket is opened and the credential provider is not invoked synchronously;
  • after _callApiKey() resolves the provider, constructing the same WebSocket surface no longer fails the credential guard.

Fresh code/security review is running on commit d2d038ff615b3e693abf8e1a01aba0a2bbd9c140.

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner September 3, 2026 22:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-16T16:12:25.005528Z 1cebb59 New commits
🔒 Security Review ✅ Completed 2026-09-16T16:14:01.756115Z 1cebb59 New commits
ℹ️ 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 chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 395125547e

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/resources/responses/ws.ts Resolved
Comment thread src/resources/responses/ws.ts Resolved

@HAYDEN-OAI HAYDEN-OAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fail-fast behavior is useful, but please preserve already-resolved function credentials before merging. I confirmed the regression described in the existing inline finding: _callApiKey() stores the token in client.apiKey and leaves _options.apiKey as a function, so the new check rejects a client that the existing WebSocket authentication path can use successfully.

Please enforce the unresolved-credential condition at the shared authentication boundary, preserving already-resolved credentials and supported provider authentication on both stable and beta surfaces. An async construction path that resolves credentials before connecting is another option. The important behavior is to prevent an unauthenticated connection without rejecting a usable resolved token.

Static review of 395125547ef1fce61aa1213bd32bf0345b4f707d; no tests run.

@HAYDEN-OAI HAYDEN-OAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes for two issues affecting both stable and beta Responses WebSocket constructors: the new protected-member access does not compile, and the guard rejects provider clients even when their credential has already been resolved. A focused TypeScript compiler check confirmed TS2445 in both changed files; the credential regression was traced through the client and WebSocket authentication paths. No tests were run.

Comment thread src/resources/responses/ws.ts Resolved
Comment thread src/resources/beta/responses/ws.ts Resolved
@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Addressed both review issues on the current head. The concrete constructors no longer access protected client options. Resolved credential validation now lives in the shared ResponsesWSBase authentication boundary, so unresolved function credentials are rejected there while a credential already resolved through _callApiKey() remains usable by both stable and beta WebSockets. Focused WebSocket tests pass (4/4), and TypeScript compilation succeeds.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d2d038ff61

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/resources/responses/ws-base.ts Resolved
@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Addressed both new findings. The shared Responses WebSocket boundary now rejects only an unresolved function-backed apiKey, while clients with caller-managed Authorization headers or other non-apiKey authentication remain allowed. Added an internal client predicate for the unresolved-function state. The acceptance test now uses a mocked ws transport and closes it, so it never opens a real network connection. Validation: 10 focused WebSocket tests passed and TypeScript --noEmit completed successfully.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5199e017f5

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/resources/responses/ws-base.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b22c606afa

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/resources/responses/ws.ts Resolved
Comment thread src/resources/responses/ws.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d1165a9d0d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/resources/responses/ws.ts Resolved
Comment thread src/resources/responses/ws.ts Resolved
Comment thread src/resources/responses/ws.ts Resolved
Preserve the invocation-local credential capture from main alongside the unresolved-key helper. Apply current formatting and regex lint rules to the existing WebSocket changes.

@HAYDEN-OAI HAYDEN-OAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed the current head and resolved eight discussions whose requested corrections are present. Four existing discussions remain unactioned.

I reproduced the existing custom-credential regression: an unresolved function key with a caller-provided string X-Auth-Token still throws before either stable or beta can connect (existing discussion). The new inline finding below also reproduces with the real ws transport: an empty static API key overrides explicitly supplied Basic authentication. These two compatibility regressions need correction before approval; I have not added duplicate findings for the other existing threads.

I also prepared a local merge with main at 425502d2, retaining its _callApiKey(capture) concurrency behavior and fixing current formatting/lint errors. Validation of that merged candidate: 328 focused tests pass on Node 22 and 24; lint, typecheck, build, and CJS/ESM stable/beta smoke checks on Node 22.0.0 and 24 pass. Separate loopback transport reproductions confirm both regressions on both surfaces. PushPatrol denied the fork push, so that merge is not yet on this PR and this review remains anchored to d1165a9d.

Comment thread src/resources/responses/ws-base.ts Resolved
Reuse the shared credential-header classification and validate serialized credential snapshots without rereading the client key. Preserve empty-key Basic authentication, resolved-key overrides, and custom transport authentication ownership. Cover stable and beta entrypoints with loopback handshakes and focused regressions.
@HAYDEN-OAI
HAYDEN-OAI self-requested a review September 16, 2026 16:10

@HAYDEN-OAI HAYDEN-OAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved at 1cebb59. The published fixes address the authentication regressions and remaining snapshot concerns; the custom base-transport contract is documented and regression-tested. All open review conversations are resolved.

Validation on this commit: 468 focused tests pass on Node 22 and 24; lint, typecheck, build, and CJS/ESM smoke checks on Node 22.0.0 and 24 pass. Independent review found no remaining actionable correctness issue. GitHub CI is still running.

@github-actions

Copy link
Copy Markdown
Contributor

Castiron custom code

✅ No new custom-code files detected.

45 mixed files remain; 5 existing customizations changed.

Compared 425502d2bf2d → 1cebb5959268. Generated baselines verified.

File Result Current custom patch
src/client.ts Existing customization changed +813 / −93
src/resources/beta/responses/ws-base.ts Existing customization changed +48 / −15
src/resources/beta/responses/ws.ts Existing customization changed +23 / −6
src/resources/responses/ws-base.ts Existing customization changed +48 / −15
src/resources/responses/ws.ts Existing customization changed +23 / −6
40 existing customizations unchanged
  • api.md
  • scripts/castiron/README.md
  • scripts/castiron/custom_code_report.py
  • scripts/castiron/test_custom_code_report.py
  • src/resources/audio/transcriptions.ts
  • src/resources/audio/translations.ts
  • src/resources/beta/agents/environments/files.ts
  • src/resources/beta/agents/sessions/sessions.ts
  • src/resources/beta/assistants.ts
  • src/resources/beta/beta.ts
  • src/resources/beta/index.ts
  • src/resources/beta/responses/internal-base.ts
  • src/resources/beta/responses/responses.ts
  • src/resources/beta/threads/index.ts
  • src/resources/beta/threads/runs/index.ts
  • src/resources/beta/threads/runs/runs.ts
  • src/resources/beta/threads/threads.ts
  • src/resources/chat/completions/completions.ts
  • src/resources/chat/completions/index.ts
  • src/resources/conversations/index.ts
  • src/resources/embeddings.ts
  • src/resources/files.ts
  • src/resources/fine-tuning/checkpoints/permissions.ts
  • src/resources/images.ts
  • src/resources/live/forks/ws-base.ts
  • src/resources/live/forks/ws.ts
  • src/resources/live/sideband/ws-base.ts
  • src/resources/live/sideband/ws.ts
  • src/resources/live/ws-base.ts
  • src/resources/live/ws.ts
  • src/resources/responses/internal-base.ts
  • src/resources/responses/responses.ts
  • src/resources/skills/skills.ts
  • src/resources/skills/versions/versions.ts
  • src/resources/vector-stores/file-batches.ts
  • src/resources/vector-stores/files.ts
  • src/resources/webhooks/index.ts
  • src/resources/webhooks/webhooks.ts
  • tests/api-resources/beta/agents/environments/files.test.ts
  • tests/lib/data-residency.test.ts

A changed generated baseline means this report cannot reliably identify which handwritten lines changed.

Inspect the custom-code diff

Download the exact patch produced by this run (requires repository access):

gh run download 35120254287 --repo openai/openai-node \
  --name castiron-custom-code-35120254287-1 --dir /tmp/castiron-custom-code-35120254287-1
git apply --stat /tmp/castiron-custom-code-35120254287-1/custom-code.patch
cat /tmp/castiron-custom-code-35120254287-1/custom-code.patch

Or reproduce it from an SDK checkout containing the vendored reporter:

git fetch --no-tags origin 425502d2bf2da1bdd37efda3b0fa5add96fc8a51 1cebb595926805d2cbd0db44bc5aec313470fe4d
python3 scripts/castiron/custom_code_report.py report \
  --base 425502d2bf2da1bdd37efda3b0fa5add96fc8a51 \
  --head 1cebb595926805d2cbd0db44bc5aec313470fe4d --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-1cebb5959268
cat /tmp/castiron-custom-code-1cebb5959268/custom-code.patch

This is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR.

Full report and patch

@HAYDEN-OAI
HAYDEN-OAI added this pull request to the merge queue Sep 16, 2026
Merged via the queue into openai:main with commit eea7618 Sep 16, 2026
24 checks passed
@openai-sdks openai-sdks Bot mentioned this pull request Sep 16, 2026
HAYDEN-OAI pushed a commit that referenced this pull request Sep 16, 2026
Automated Release PR
---


##
[7.17.0](v7.16.0...v7.17.0)
(2026-09-16)


### Features

* **api:** add compaction progress events
([#2749](#2749))
([425502d](425502d))


### Bug Fixes

* **ci:** retry transient Deno download failures
([#2752](#2752))
([e39037b](e39037b))
* preserve chat runner abort reasons
([#2607](#2607))
([eda4d0c](eda4d0c))
* **realtime:** preserve native WebSocket error causes
([#2715](#2715))
([58fa72a](58fa72a))
* **responses:** reject function-based API keys in WebSocket
constructors
([#2586](#2586))
([eea7618](eea7618))
* **runners:** reject unfinished turns in streaming runTools
([#2716](#2716))
([937ed67](937ed67))
* **streaming:** emit terminal SSE events missing a trailing blank line
([#2726](#2726))
([94d6418](94d6418))
* **zod:** omit impossible optional branch in strict schemas
([#2751](#2751))
([2b4c2c7](2b4c2c7))


### Chores

* update lint tooling and tailor anti-slop for the SDK
([#2753](#2753))
([21a03c2](21a03c2))


### Documentation

* **examples:** preserve split UTF-8 in raw stream consumer
([#2714](#2714))
([f44152a](f44152a))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: openai-sdks[bot] <284451331+openai-sdks[bot]@users.noreply.github.com>
@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Thanks for the careful re-review and merge. I appreciate the help getting the WebSocket authentication boundary and regression coverage into shape.

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.

2 participants