Repository navigation
[Codex Security] Unbounded StepCode sessions enable process-exhaustion DoS #846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,24 +195,39 @@ export function asRecord(value: unknown): Record<string, unknown> { | |
| /** | ||
| * The text StepCode should be asked for on this turn. | ||
| * | ||
| * Only the final user message crosses `query.input`; earlier turns live in the process' session, | ||
| * Only the newest user message crosses `query.input`; earlier turns live in the process' session, | ||
| * because the wire reduces every message to text and images. | ||
| */ | ||
| function userMessageText(message: OcxParsedRequest["context"]["messages"][number]): string | undefined { | ||
| if (message.role !== "user") return undefined; | ||
| if (!Array.isArray(message.content)) { | ||
| return typeof message.content === "string" && message.content.trim().length > 0 | ||
| ? message.content | ||
| : undefined; | ||
| } | ||
| const text = message.content | ||
| .filter(part => part.type === "text") | ||
| .map(part => (part as { text: string }).text) | ||
| .join("") | ||
| .trim(); | ||
| return text.length > 0 ? text : undefined; | ||
| } | ||
|
|
||
| export function pendingUserText(parsed: OcxParsedRequest): string | undefined { | ||
| for (let index = parsed.context.messages.length - 1; index >= 0; index -= 1) { | ||
| const message = parsed.context.messages[index]; | ||
| if (!message || message.role !== "user") continue; | ||
| if (!Array.isArray(message.content)) { | ||
| return typeof message.content === "string" && message.content.length > 0 | ||
| ? message.content | ||
| : undefined; | ||
| } | ||
| const text = message.content | ||
| .filter(part => part.type === "text") | ||
| .map(part => (part as { text: string }).text) | ||
| .join("") | ||
| .trim(); | ||
| if (text.length > 0) return text; | ||
| if (message?.role === "user") return userMessageText(message); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clear a held call's routing state when an empty replacement is refused.
Before this change, the same request reached the cleanup path and released the query. Validate the replacement text before consuming the hold, or restore the hold before returning from the refusal. Keep nonempty replacement text and matching results unchanged.
|
||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| /** User text that starts a new process, excluding closed assistant turns and orphaned tool results. */ | ||
| export function newConversationUserText(parsed: OcxParsedRequest): string | undefined { | ||
| for (let index = parsed.context.messages.length - 1; index >= 0; index -= 1) { | ||
| const message = parsed.context.messages[index]; | ||
| if (!message) continue; | ||
| if (message.role === "assistant" || message.role === "toolResult") return undefined; | ||
| if (message.role === "user") return userMessageText(message); | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,9 @@ permission denials. | |
| each session before workspace setup, so shutdown can close an opening session before it spawns. | ||
| At eight owned sessions a home pool refuses new conversations with retryable `step_cli_pool_full`. | ||
| Existing handles and coalesced opens still work. Only confirmed cleanup releases capacity. | ||
| Before `sessions.open` can allocate a process, a new handle must carry non-whitespace user text. | ||
| Empty, model-only and orphan-result requests receive `step_cli_no_user_text`; an existing live handle | ||
| still reaches held-call matching, so a legitimate tool result can continue its original query. | ||
|
Comment on lines
+46
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 The public StepCode guide omits the new startup requirement The public StepCode guide does not explain that new conversations require non-blank user text. Document the Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| The pool retains ownership of adapter, idle-timer and sweep closes until termination is | ||
| confirmed. Shutdown drains those receipts and propagates failures. | ||
| Closing handles refuse replacement. Session close is idempotent and clears held-request timers. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,6 +176,23 @@ function host(session: FakeSession): StepConversationHost & { ref: StepConversat | |
| }; | ||
| } | ||
|
|
||
| /** A host with no session until `open`, used to distinguish admission from existing continuation. */ | ||
| function unopenedHost(session: FakeSession): StepConversationHost & { openCount(): number } { | ||
| const base = host(session); | ||
| let openedHandle: string | undefined; | ||
| let opens = 0; | ||
| return { | ||
| ...base, | ||
| get: ref => ref?.handle === openedHandle ? session : undefined, | ||
| open: async ref => { | ||
| opens += 1; | ||
| openedHandle = ref.handle; | ||
| return session; | ||
| }, | ||
| openCount: () => opens, | ||
| }; | ||
| } | ||
|
|
||
| function provider() { | ||
| return { | ||
| adapter: "step-cli", | ||
|
|
@@ -200,6 +217,56 @@ function parsed(messages: unknown[]): OcxParsedRequest { | |
|
|
||
| const USER_ASK = [{ role: "user", content: "run it", timestamp: 0 }]; | ||
|
|
||
| describe("StepCode pre-allocation admission", () => { | ||
| test("non-actionable new conversations are refused without opening a session", async () => { | ||
|
Comment on lines
+220
to
+221
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| const cases: unknown[][] = [ | ||
| [], | ||
| [ | ||
| { role: "user", content: "historical question", timestamp: 0 }, | ||
| { role: "assistant", content: "model-only history", timestamp: 1 }, | ||
| ], | ||
| [{ role: "user", content: " \t\n ", timestamp: 0 }], | ||
| [ | ||
| { role: "user", content: "historical question", timestamp: 0 }, | ||
| { role: "toolResult", toolCallId: "orphan", toolName: "shell", content: "result", timestamp: 1 }, | ||
| ], | ||
| ]; | ||
| for (const messages of cases) { | ||
| const session = new FakeSession(); | ||
| const conversation = unopenedHost(session); | ||
| const events: AdapterEvent[] = []; | ||
| await createStepCliAdapter(provider(), { openSession: conversation }).runTurn!( | ||
| parsed(messages), | ||
| THREAD_META, | ||
| event => events.push(event), | ||
| ); | ||
| expect(conversation.openCount()).toBe(0); | ||
| expect(session.handshakeCount).toBe(0); | ||
| expect(events).toMatchObject([{ type: "error", code: "step_cli_no_user_text", status: 400 }]); | ||
| } | ||
| }); | ||
|
|
||
| test("ordinary user text still opens a session and runs the query", async () => { | ||
| const session = new FakeSession(); | ||
| const conversation = unopenedHost(session); | ||
| const events: AdapterEvent[] = []; | ||
| session.stream = [TURN_COMPLETE]; | ||
| await createStepCliAdapter(provider(), { openSession: conversation }).runTurn!( | ||
| parsed([ | ||
| { role: "user", content: "historical question", timestamp: 0 }, | ||
| { role: "assistant", content: "historical answer", timestamp: 1 }, | ||
| { role: "user", content: "run it", timestamp: 2 }, | ||
| ]), | ||
| THREAD_META, | ||
| event => events.push(event), | ||
| ); | ||
| expect(conversation.openCount()).toBe(1); | ||
| expect(session.handshakeCount).toBe(1); | ||
| expect(session.inputs[0]?.text).toContain("run it"); | ||
| expect(events.find(event => event.type === "done")).toMatchObject({ stopReason: "stop" }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("StepCode reverse requests are always answered", () => { | ||
| test("a permission request with no turn is denied", () => { | ||
| const session = new FakeSession(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Existing conversations no longer skip empty user content blocks
A trailing user message with blank text blocks now stops prompt selection; previously it fell back to earlier user text. Cover this case on a live session to make the intended behavior explicit.
Was this helpful? React with 👍 or 👎 to provide feedback.