Repository navigation
Conversation
Closes the review's P1 set (M2, M3, M4, M15) on top of the PR QA branch. M2 — CORS echoed a fixed `*` alongside `Allow-Credentials: true`, which is unusable: a wildcard origin forbids credentials. The configured Origin is now echoed back (plus `Vary: Origin`), and only when it is in the allowlist, so `Allow-Credentials` becomes meaningful and a future Cookie session keeps working. M4 — the WebSocket upgraders accepted any origin and the two /ws routes sat behind no middleware at all, so knowing an instance_id or app_id was enough to open a socket. Handshakes now require a valid JWT before the upgrade (401 otherwise) and check the same Origin allowlist as CORS (403 for a foreign origin). The adapter gateway upgrader takes the list through GatewayConfig.AllowedOrigin. Tokens are accepted via ?token= (Python bridges, updated here), Authorization: Bearer, or the `espl` subprotocol, which is the only header a browser can set on a WebSocket. Requests without an Origin are non-browser clients and pass. M3 — the shipped JWT secret was used with no check. Startup now WARNs while the placeholder (or an empty secret) is in place, with a fix hint. A prefix comparison would misfire, so a secret that merely contains the placeholder text still counts as rotated. M15 — http.Server had only Addr and Handler. All four timeouts are wired from config, and a global MaxBodyBytes middleware caps request bodies: a declared oversize is refused with 413 up front, an undeclared one is caught by http.MaxBytesReader. One `security.allowed_origins` list drives CORS, both socket upgraders and the gateway, so they cannot drift; ESP_SECURITY_ALLOWED_ORIGINS overrides it without editing the file. Every item has a test, including the cases that used to pass silently (garbage token accepted, foreign origin accepted). Docs touched: api-reference (WS auth table, CORS, limits, 413), SECURITY, CONTRIBUTING, and the review's own status marks. Co-authored-by: multica-agent <github@multica.ai>
TyperBody
force-pushed
the
agent/qjy/espl-20-p1-security
branch
from
November 7, 2026 11:47
5beee1c to
1101d87
Compare
TyperBody
added a commit
that referenced
this pull request
Nov 7, 2026
Third stacked PR; P1 (#5) and P0 (#6) both touch websocket.go and its test, so the pair only merges with resolution. Same treatment as the P2 merge: union the two sides rather than pick. - websocket.go: both imports (P0 needs message, P1 needs middleware); both sockets keep the pre-upgrade authenticateWS check - websocket_test.go: keep P0's hub fixtures and P1's handshake-auth and Origin cases in one file, with P1's helper renamed to dialPlain to avoid the method-name collision, and one TestMain - P0's fixture dials now carry a token, since the handshake refuses an unauthenticated upgrade; the separator is & because the path already has a query string - functional-review.md: combine the P2 and P1 fix-list annotations Verified on one build with all three PRs: three keyless ingests 201/201/ 201, duplicate register 409, delete-missing 404, cross-origin preflight without Allow-Origin, 8 MB body 413, WS without token 401. go vet, gofmt (0), golangci-lint (0 issues) and the full suite pass.
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.
P1 security/deployability set from
docs/developer-guide/functional-review.md(M2, M3, M4, M15). Base isfeat/project-review-and-pr-qa(PR #3), per the task; nothing from #3 is merged in, this is one commit on top of it.What changed
M2 — CORS (
internal/middleware/middleware.go)Allow-Origin: *+Allow-Credentials: trueis a contradiction: a wildcard origin forbids credentials, and the front end would silently lose them the day it uses Cookies. The middleware now echoes the requestOriginback only when it is in the allowlist, keepsAllow-Credentials: true, and addsVary: Originso a shared cache cannot serve one client's CORS headers to another. Requests with noOrigin(curl, the Python bridges, health checks) get no CORS headers and are otherwise untouched.M4 — WebSocket handshake (
internal/handler/websocket.go,internal/adaptergateway/gateway.go)The two
/wshandlers sat behind no middleware andCheckOriginreturnedtrue, so anyone who knew aninstance_id/app_idcould open a socket. Now:Originis refused with 403 by the upgrader, checked against the same list CORS uses;GatewayConfig.AllowedOrigin, so all three socket surfaces agree;Originis a non-browser client and passes.Tokens are accepted via
?token=(the Python bridges — updated here),Authorization: Bearer, orSec-WebSocket-Protocol: espl, <jwt>(the only header a browser can set onWebSocket).M3 — placeholder JWT secret (
internal/config/config.go,internal/server/server.go)Startup logs a WARN while the shipped value (or an empty secret) is in place, with a fix hint. WARN rather than refuse-to-boot so existing deployments keep running.
UsingPlaceholderJWTSecretrequires an exact match: a secret that merely contains the placeholder text is a real rotation and must not warn.M15 — server limits (
internal/server/server.go,internal/middleware/middleware.go)All four timeouts (
ReadHeaderTimeout/ReadTimeout/WriteTimeout/IdleTimeout) are wired fromserver.*config, default 10s/60s/120s/120s,0= disabled. A globalMaxBodyBytesmiddleware enforcesserver.max_body_bytes(default 4 MiB): a declared oversize is refused with 413 up front, an undeclared one is caught byhttp.MaxBytesReader.One allowlist.
security.allowed_originsdrives CORS, both socket upgraders and the gateway, so they cannot drift;ESP_SECURITY_ALLOWED_ORIGINS(comma-separated) overrides it without editing the file.Verification
Every item has tests that fail on the old code, including the cases that used to pass silently (garbage token accepted, cross-origin accepted, no timeout):
End-to-end, real server on a temp port (
CGO_ENABLED=1build), before → after:OPTIONS, allowlisted OriginAllow-Origin: *204,Allow-Origin: http://allowed.example,Allow-Credentials: true,Vary: OriginOPTIONS, foreign OriginAllow-Origin: *204, noAllow-OriginGET /ws/app?app_id=…no token101401…&token=total-garbage1014011014031011014132.0s(configuredReadHeaderTimeout)Notes for review
instance_idis M1 and still open.?token=is now required — without it they would 401-loop. Only the URL builder and one import changed.security.allowed_originsdefaults tolocalhostonly. A real deployment must add its front-end origin; documented inSECURITY.mdandCONTRIBUTING.mdrather than left to fail at runtime.Rebase note
The base moved while this was open:
8e764e7(ci: run on stacked PRs…) landed the sameCI-trigger fix I had also written, so my duplicate commit was dropped and this is now one
commit on current
feat/project-review-and-pr-qa. Nothing from #3 is merged in.That trigger fix is also what makes the checks below run at all — before it, a PR into a
feature branch got zero checks because
branchesmatches the base.CI
All four checks green on
1101d87: backend (vet, build, test), frontend (tsc, vite build),generated artifacts, format and lint.