fix(hardening): close DoS, traversal, and crypto-correctness gaps#8
Merged
Conversation
…move import hacks Audit pass over the whole codebase. Each item is substantiated by reading the affected code; tests added for every behavioural change. Security / robustness - api: bound request bodies with http.MaxBytesReader (8 MiB) and set baseline response headers (nosniff, X-Frame-Options DENY, no-referrer) via a router middleware. NewMux now returns http.Handler. - api: cap policy_yaml at 64 KiB before policy.Parse so a YAML alias/anchor bomb cannot burn CPU in the parser (413 on oversize). - cli(serve): add ReadTimeout/WriteTimeout/IdleTimeout so a slow-body or slow-read client can no longer pin a handler goroutine (Slowloris). - cli(root): validate the --id flag in a PersistentPreRunE so a scripted `--id ../../etc` is rejected before any subcommand builds a tenant path. Adds tenant.ValidateID; tenantSubdir/defaultIngestOutPath now use filepath.Join instead of string concatenation. - mcp: validate the themis_bom hash as 64 lowercase hex chars (matching the REST layer) before composing the URL path. - sign: CosignKeylessStub.Verify now enforces the certificate validity window instead of silently accepting expired/not-yet-valid certs — the short-lived-cert property is the security premise of keyless signing. - auth(oidc): key the userinfo cache on sha256(token) so a heap dump cannot leak live bearer tokens, and bound the IdP call with a 10s timeout so a stalled IdP cannot hang the handler. Correctness / best practices - api(overrides): handleOverrideClosePM no longer discards the readTenantEvents error (was returning 200 with empty state on failure). - mcp: thread the request context through handleLine → handleToolCall → httpGET so outbound API calls are cancellable. - heartbeat: drop the dead single-goroutine mutex in Watch. - Remove three "keep imports tidy" blank-identifier hacks (errors/filepath/strings) and their now-unused imports.
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.
Summary
Codebase audit pass. Build,
go vet,golangci-lint(0 issues), the full race test suite, and the per-package coverage gate (global 88.2% ≥ 87.0%) all pass. Every behavioural change has a test.Security / robustness
apibody limithttp.MaxBytesReader(8 MiB) + baseline security headers (nosniff,X-Frame-Options: DENY,Referrer-Policy: no-referrer) via router middleware.NewMuxnow returnshttp.Handler.apipolicy bombpolicy_yamlat 64 KiB beforepolicy.Parse(alias/anchor-bomb defence); returns 413.cli servetimeoutsReadTimeout/WriteTimeout/IdleTimeout— closes Slowloris-class goroutine pinning.clitenant traversalPersistentPreRunEvalidates--idbefore any subcommand builds a path;tenant.ValidateIDadded;tenantSubdir/defaultIngestOutPathusefilepath.Join.mcphash validationthemis_bomhash validated as 64 lowercase hex chars before composing the URL path.signcert expiryCosignKeylessStub.Verifynow enforces the cert validity window instead of silently accepting expired certs.auth/oidctoken cachesha256(token)(no plaintext tokens in memory); IdP call bounded by a 10s timeout.Correctness / best practices
api/overrides:handleOverrideClosePMno longer discards thereadTenantEventserror (was a silent 200 with empty state).mcp: request context threaded throughhandleLine → handleToolCall → httpGETso outbound calls are cancellable.heartbeat: removed the dead single-goroutine mutex inWatch.errors/filepath/strings) and their unused imports.Out of scope (noted, not changed)
RequireIdentityhardwiresFileTokenStore). This is documented Plan-18 future work and needs an operator-facing config mechanism to select the store — a feature, not a bug fix.tokens revokesubstring matching is intentional/documented operator behaviour.Test plan
go build ./...,go vet ./...golangci-lint run ./...→ 0 issuesgo test -race ./...→ all passscripts/cover_check.sh) → PASS