Repository navigation
fix(security,resilience): pre-release hardening from deep stress test #503
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bca3aad
fix(security,resilience): pre-release hardening from deep stress test
ndycode f7e19fe
chore(release): cut v2.1.13-beta.3 + bump vitest to ^4.1.8
ndycode 4f0eefc
fix: address #503 review (dir-mode + retry/strip coverage + version p…
ndycode 3dcc500
fix: address #503 round-2 review (chmod error handling + win32/strip …
ndycode 638a207
test(observability): assert snapshot temp file is written 0o600
ndycode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: address #503 review (dir-mode + retry/strip coverage + version p…
…ins) - runtime/runtime-observability.ts: re-assert dir 0o700 via fs.chmod after mkdir — mkdir's mode is a no-op on a pre-existing multi-auth dir, so the upgrade path kept old (possibly permissive) perms. POSIX-only, best-effort. - Bump .codex-plugin/plugin.json + AGENTS.md to 2.1.13-beta.3 (plugin-manifest test asserts manifest version == package version; the beta.3 bump left them stale). Tests: - local-bridge + runtime-rotation-proxy: assert inbound `proxy-authorization` (alongside cookie) is stripped on the outbound request, so a refactor dropping the delete is caught. - quota-cache: read-retry (EACCES) + rename-retry (ENOTEMPTY) + last-write-wins queue-ordering regressions, pinning the widened retry taxonomy. - runtime-observability-dir-mode (new, POSIX-only): pre-create CODEX_MULTI_AUTH_DIR world-writable, persist a snapshot, assert the dir becomes owner-only — proves the chmod-after-mkdir hardening on the upgrade path. - runtime-observability test fs-mock now exposes chmod. typecheck + lint + audit:ci clean; full suite 4249 passed / 2 skipped.
- Loading branch information
commit 4f0eefce1b977cf66afc195c3f35ff2c169c80fa
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
ndycode marked this conversation as resolved.
Resolved
|
||
| import { promises as fs, rmSync, statSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { tmpdir } from "node:os"; | ||
| import { sleep } from "../lib/utils.js"; | ||
|
|
||
| // Windows-safe recursive remove with EBUSY/EPERM backoff, mirroring the | ||
| // removeDirectoryWithRetry helper in codex-bin-wrapper.test.ts. A bare fs.rm | ||
| // can flake on Windows when an antivirus/indexer briefly locks the just-written | ||
| // snapshot file. | ||
| function isRetriableFsError(error: unknown): boolean { | ||
| if (!error || typeof error !== "object" || !("code" in error)) { | ||
| return false; | ||
| } | ||
| const { code } = error as { code?: unknown }; | ||
| return code === "EBUSY" || code === "EPERM"; | ||
| } | ||
|
|
||
| async function removeDirectoryWithRetry(dir: string): Promise<void> { | ||
| const backoffMs = [20, 60, 120]; | ||
| let lastError: unknown; | ||
| for (let attempt = 0; attempt <= backoffMs.length; attempt += 1) { | ||
| try { | ||
| rmSync(dir, { recursive: true, force: true }); | ||
| return; | ||
| } catch (error) { | ||
| lastError = error; | ||
| if (!isRetriableFsError(error) || attempt === backoffMs.length) { | ||
| break; | ||
| } | ||
| await sleep(backoffMs[attempt]); | ||
| } | ||
| } | ||
| throw lastError; | ||
| } | ||
|
ndycode marked this conversation as resolved.
Resolved
|
||
|
|
||
| describe("runtime observability snapshot dir hardening", () => { | ||
| let tempRoot: string; | ||
| let snapshotDir: string; | ||
| let originalDir: string | undefined; | ||
| let originalVitest: string | undefined; | ||
|
|
||
| beforeEach(async () => { | ||
| originalDir = process.env.CODEX_MULTI_AUTH_DIR; | ||
| originalVitest = process.env.VITEST; | ||
| tempRoot = await fs.mkdtemp(join(tmpdir(), "codex-obs-dirmode-")); | ||
| // Pin the multi-auth dir to a deterministic temp subdir; getCodexMultiAuthDir | ||
| // returns CODEX_MULTI_AUTH_DIR verbatim when set. | ||
| snapshotDir = join(tempRoot, "multi-auth"); | ||
| process.env.CODEX_MULTI_AUTH_DIR = snapshotDir; | ||
| // PERSIST_RUNTIME_SNAPSHOT is computed at module load as VITEST !== "true", | ||
| // so blank it before the dynamic import to enable on-disk persistence. | ||
| process.env.VITEST = ""; | ||
| vi.resetModules(); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| if (originalDir === undefined) { | ||
| delete process.env.CODEX_MULTI_AUTH_DIR; | ||
| } else { | ||
| process.env.CODEX_MULTI_AUTH_DIR = originalDir; | ||
| } | ||
| if (originalVitest === undefined) { | ||
| delete process.env.VITEST; | ||
| } else { | ||
| process.env.VITEST = originalVitest; | ||
| } | ||
| await removeDirectoryWithRetry(tempRoot); | ||
| }); | ||
|
|
||
| it.skipIf(process.platform === "win32")( | ||
| "re-asserts owner-only (0o700) dir mode on a pre-existing permissive dir", | ||
| async () => { | ||
| // Upgrade path: the multi-auth dir already exists with permissive perms, | ||
| // so mkdir({ mode: 0o700 }) is a no-op and only the explicit chmod can | ||
| // tighten it. | ||
| await fs.mkdir(snapshotDir, { recursive: true }); | ||
| await fs.chmod(snapshotDir, 0o777); | ||
| expect(statSync(snapshotDir).mode & 0o777).toBe(0o777); | ||
|
|
||
| const mod = await import("../lib/runtime/runtime-observability.js"); | ||
| mod.mutateRuntimeObservabilitySnapshot((snapshot) => { | ||
| snapshot.responsesRequests = 1; | ||
| }); | ||
|
|
||
| const snapshotPath = join(snapshotDir, "runtime-observability.json"); | ||
| await vi.waitFor(() => { | ||
| expect(statSync(snapshotPath).isFile()).toBe(true); | ||
| }); | ||
|
|
||
| // chmod runs before the snapshot file is written, so the dir is tightened | ||
| // by the time the file exists. | ||
| expect(statSync(snapshotDir).mode & 0o777).toBe(0o700); | ||
| }, | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.