Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
/**
* CodeQL alert 811 — js/double-escaping (HIGH) on
* `open-sse/vendor/codex-chatgpt-web/adapters/chatgpt-web/environment.ts`.
*
* `decodeXmlText()` unescapes the XML entities of the trusted Codex
* `<environment_context>` block. It decoded `&` BEFORE `"` / `'`,
* so the `&` it produced was re-consumed by a later `replaceAll` and the text
* was unescaped twice: `&quot;` collapsed to `"` instead of `"`.
*
* These values become sandbox `cwd` / `workspace_roots` paths, so a
* double-unescape silently rewrites the trusted workspace boundary.
* `&` must be decoded LAST.
*/
import test from "node:test";
import assert from "node:assert/strict";
import { extractChatGptTurnEnvironment } from "../../open-sse/vendor/codex-chatgpt-web/adapters/chatgpt-web/environment.ts";
function parsedRequestWithCwd(cwdLiteral: string) {
const environmentText = [
"<environment_context>",
` <cwd>${cwdLiteral}</cwd>`,
" <sandbox_mode>read-only</sandbox_mode>",
"</environment_context>",
].join("\n");
const turnMetadata = { internal_chat_message_metadata_passthrough: { turn_id: "turn-1" } };
return {
context: { tools: [] },
_rawBody: {
client_metadata: {
"x-codex-turn-metadata": JSON.stringify({ thread_id: "thread-1", turn_id: "turn-1" }),
},
input: [
{ type: "message", role: "system", content: [{ type: "input_text", text: "sys" }] },
{
type: "message",
role: "user",
content: [{ type: "input_text", text: environmentText }],
...turnMetadata,
},
{
type: "message",
role: "user",
content: [{ type: "input_text", text: "hello" }],
...turnMetadata,
},
],
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;
}
test("decoding the trusted Codex environment does not double-unescape &quot;", () => {
const env = extractChatGptTurnEnvironment(parsedRequestWithCwd("/tmp/ws&quot;dir"));
assert.equal(
env.cwd,
"/tmp/ws"dir",
'`&quot;` must decode to the literal text `"`, not to a double-unescaped `"`'
);
});
test("decoding the trusted Codex environment does not double-unescape &lt; / &#39;", () => {
assert.equal(
extractChatGptTurnEnvironment(parsedRequestWithCwd("/tmp/ws&lt;dir")).cwd,
"/tmp/ws<dir"
);
assert.equal(
extractChatGptTurnEnvironment(parsedRequestWithCwd("/tmp/ws&#39;dir")).cwd,
"/tmp/ws'dir"
);
});
test("single-level XML entities still decode normally", () => {
assert.equal(extractChatGptTurnEnvironment(parsedRequestWithCwd("/tmp/a&b")).cwd, "/tmp/a&b");
assert.equal(
extractChatGptTurnEnvironment(parsedRequestWithCwd("/tmp/a"b")).cwd,
'/tmp/a"b'
);
assert.equal(extractChatGptTurnEnvironment(parsedRequestWithCwd("/tmp/a'b")).cwd, "/tmp/a'b");
assert.equal(extractChatGptTurnEnvironment(parsedRequestWithCwd("/tmp/a>b")).cwd, "/tmp/a>b");
});