Repository navigation
fix: admin endpoint security hardening — CSRF, PID recycle, fsync perf - #81
Closed
ranxianglei wants to merge 1 commit into
Closed
ranxianglei wants to merge 1 commit into
ranxianglei wants to merge 1 commit into
Conversation
…ints Rework of PR #81 onto current master. The original PR also hardened codex-takeover.ts (PID-recycling defense + fsync perf), but that file was removed from master, so only the server.ts CSRF defense survives here. - isTrustedAdminOrigin: pin Host hostname to loopback (127.0.0.1/localhost/::1) so a rebinding domain (evil.com -> 127.0.0.1) can no longer pass Origin===Host. - reject Sec-Fetch-Site other than same-origin (fetch metadata, unforgeable by browser JS); non-browser clients send neither header and are unaffected. - test: admin endpoints return 403 for non-loopback Host and cross-site Sec-Fetch-Site. 371/371 tests pass, typecheck clean, build OK.
ranxianglei
force-pushed
the
fix/admin-security-hardening
branch
from
August 13, 2026 13:17
faec567 to
7540e60
Compare
cskwork
pushed a commit
to cskwork/billion-context
that referenced
this pull request
Oct 21, 2026
…ints Rework of PR ranxianglei#81 onto current master. The original PR also hardened codex-takeover.ts (PID-recycling defense + fsync perf), but that file was removed from master, so only the server.ts CSRF defense survives here. - isTrustedAdminOrigin: pin Host hostname to loopback (127.0.0.1/localhost/::1) so a rebinding domain (evil.com -> 127.0.0.1) can no longer pass Origin===Host. - reject Sec-Fetch-Site other than same-origin (fetch metadata, unforgeable by browser JS); non-browser clients send neither header and are unaffected. - test: admin endpoints return 403 for non-loopback Host and cross-site Sec-Fetch-Site. 371/371 tests pass, typecheck clean, build OK.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Addresses PR#73 review items #5/#6/#7 (the medium-priority items deferred from the initial merge).
#5 DNS-rebinding CSRF defense (
server.ts)isTrustedAdminOriginnow:Origin===Hostcheck because both carried the attacker domain.Sec-Fetch-Site: rejects anything that is notsame-origin. This is a fetch metadata header that browser JS cannot forge.Non-browser clients (curl, etc.) send neither Origin nor Sec-Fetch-Site — unaffected.
#6 PID-recycling defense (
codex-takeover.ts)pidStartTick(Linux/proc/<pid>/statfield 22) alongsidepidin route state.pidAlivenow compares the start tick — a dead bili's recycled PID is no longer mistaken for the live owner.process.kill(pid, 0)(unchanged).#7 Per-request fsync overhead (
codex-takeover.ts)atomicWrite/writeStategain adurableparam (defaulttrue).recordCodexRouteRequestwrites withdurable=false(skipsfsync) — the last-seen timestamp is non-critical; atomic rename still guarantees consistency. Critical state (claim/disable) keepsfsync.Tests
Sec-Fetch-Site→ 403pidStartTickpresence afterenableCodexTakeover226 tests pass, typecheck clean, build OK.