Repository navigation
v1.1.0
go-bananas v1.1.0
Summary
v1.1.0 is a security hardening release. It fixes every verified finding from a
2026-11 security review of the framework, changes several defaults to safe
values, and adds a native Go fuzz suite (39 targets, run nightly in CI).
Three issues are exploitable on v1.0.x and have advisories:
- GHSA-g2rq-85pp-c2j9: CSRF bypass through
middleware.MutateMethod. Also fixed in v1.0.2. - GHSA-93pv-fv98-p53j: key-version path traversal in
keys.(*Filesystem).Decrypt. Also fixed in v1.0.2. - GHSA-fqhp-2jm8-w3vm: split session cookies survive logout and expiry in
middleware.RequireSession. Also fixed in v1.0.2.
v1.0.2 is a patch release that carries only these three fixes, for anyone
who can't take the v1.1.0 default changes yet.
No exported signatures change except by gaining trailing variadic options (see
API changes). Ciphertext and cookie formats are unchanged. See
Rollback before relying on a downgrade.
Upgrading: read Migration from v1.0.x before you
bump. Several changes compile cleanly but change runtime behavior.
Go toolchain
Build with Go ≥ 1.27.4. Go 1.27.0–1.27.3 are affected by GO-2026-6859
(net/http), which is reachable from go-bananas servers. The module's go
directive stays at 1.27, so update your CI and build images yourself, and run
govulncheck ./.... go-bananas CI now pins 1.27.4 and runs a pinned
govulncheck.
Security fixes
Found by a security review of the codebase unless noted otherwise.
| Severity | Area | Fix |
|---|---|---|
| High | middleware.MutateMethod |
Only POST can be overridden, only to PUT/PATCH/DELETE, only from a urlencoded body (≤ 64 KB, never multipart, never the query string). Previously a POST with _method=GET reached the POST handler while HandleCSRF saw a GET and skipped validation. (GHSA-g2rq-85pp-c2j9) |
| High | Split session cookies | A captured _gbs-<key> split cookie, replayed without its main session cookie, was joined into a fresh session, so values stored there outlived logout and max age. Split cookies are now bound to their main session by a random ID (stored under the reserved session key "_gbs_binding") and expired with it. Found during this release's build. (GHSA-fqhp-2jm8-w3vm; also fixed in v1.0.2) |
| Low | keys.Filesystem (development provider) |
Decrypt used the ciphertext's version prefix as a path element without validation, so ../otherKey/<ver>:… decrypted with a different key under the same root. Versions must now be decimal digits; reads go through os.OpenRoot. (GHSA-93pv-fv98-p53j) |
| Medium | middleware.SecureHeaders |
No longer trusts X-Forwarded-Host for the HTTPS redirect (open redirect and cache poisoning). New WithSSLHost, WithAllowedHosts, WithTrustedHostHeaders. |
| Medium | Template serverEndpoint |
No longer derived from the client Host header outside dev mode. New TemplateConfig.AllowedHosts. |
| Medium | cookiestore.New |
Cookies are always HttpOnly and Secure; SameSite defaults to Lax; SameSite=None forces Secure; the caller's options are no longer mutated. New WithInsecureCookies() for local HTTP dev. |
| Medium | Sessions | Sessions record a creation time. New opt-in middleware.CheckSessionMaxAge enforces an absolute lifetime. |
| Medium | server.ServeHTTPHandler |
Adds ReadTimeout 5m and IdleTimeout 120s (slow-read and idle-connection exhaustion). |
| Medium | secrets/vault |
References without ?version= read the latest version instead of version 1, so rotation takes effect. |
| Medium | keys/azure |
Encrypt errors on non-empty AAD instead of silently ignoring it. |
| Medium | cache.WriteThruLookup |
The backend lookup no longer holds the cache-wide lock; concurrent callers coalesce per key. |
| Low | middleware.HandleCSRF |
Form bodies are capped at 1 MiB before parsing (was up to 32 MiB plus temp files, before authentication). Multipart temp files are removed. TRACE is no longer a safe method. |
| Low | Azure vault names | Validated against ^[A-Za-z0-9-]{3,24}$ so a crafted name can't send the bearer token to another host. |
| Low | keys/vault |
Sign sends key_version, so signatures match the advertised key after rotation. |
| Low | render.RenderCSV |
Content-Disposition filename is encoded with mime.FormatMediaType (parameter injection). |
| Low | render.RenderJSON |
The error body is always valid JSON. |
| Low | toJSON template func |
Returns template.JS of escaped JSON (was []byte). |
| Low | HSTS | preload is now opt-in (WithHSTSPreload). |
| Low | flash |
No panic when a session flash key holds a non-map value. |
| Low | response.Back |
Follows only same-host http/https referrers; strips userinfo. |
| Low | cache.New |
TTLs above 100 years are rejected (overflow made every Set miss); one purge goroutine per expired key. |
| Low | examples/ssr-oidc |
Logout is POST with CSRF; constant-time state and nonce compare; flow state cleared before the response; admin requires email_verified; OAuth error handled. Outside dev mode, SecureHeaders is pinned with WithAllowedHosts (from ALLOWED_HOSTS) or WithSSLHost (from the host of SERVER_ENDPOINT), so other Host values get 400. |
| Low | CI supply chain | Every workflow (ci.yml, fuzz.yml, pages.yml, codeql-analysis.yml) pins actions by commit SHA with persist-credentials: false; govulncheck is version-pinned; the fuzz workflow uploads no artifacts and has contents: read only. |
Found by fuzzing
renderjoinStrings/toSentencepanicked on a nil value, so
{{joinStrings .missing ", "}}returned a 500. They now render"".response.RealHostFromRequestdropped IPv6 brackets
(https://2001:db8::1:8443); it now usesnet.JoinHostPortand returns
https://[2001:db8::1]:8443.::1(with or without brackets) now counts as
localhost and getshttp:http://[::1]:8080, where v1.0.x gave
https://::1:8080.
Other fixes
keys.Filesystem.Encryptpicks the latest version numerically (it compared as
text, so9beat10), andSigningKeyVersionsskips stray non-numeric files
instead of failing.keys/azure.SigningKeyVersionsworks (it failed on every call), returns
VAULT/KEY/VERSIONIDs, sorts newest first, and omits disabled versions.keys/vault.SigningKeyVersionssorts newest first, andparseKeyIDaccepts
thename/Nform thatKeyID()returns.secretsCacher fetches run on a context detached from every caller's
cancellation and deadline, with a fixed 30s timeout, so one cancelled
request no longer fails coalesced callers.- The 404 and 405 pages in the example now carry the security headers.
New: fuzz suite
Native go test -fuzz targets live next to the code, with seeds in
testdata/fuzz/ that replay in every go test. make fuzz runs every target;
a nightly workflow runs each for 60s.
Migration from v1.0.x
Use the upgrade skill. skills/go-bananas-upgrade
is the authoritative list: it gives a grep, an "affected if" and an exact fix
for every item below, and flags the items that need a human decision. Install it
with /plugin marketplace add mikehelmick/go-bananas and ask Claude Code to
"upgrade go-bananas to v1.1". Scan before you bump: the build alone won't
catch most of these.
Docs: middleware chain,
sessions and CSRF,
server,
secrets and keys,
rendering,
cache.
The numbers below match the skill's entries.
Routing and CSRF
MutateMethodignores_methodin the query string, in multipart
bodies, in urlencoded bodies over 64 KB or that fail strict parsing, on
non-POST requests, and for targets other than PUT/PATCH/DELETE; the request
stays POST. Underr.Useit only changes what later handlers see, not which
route matches. Wrap the router (middleware.MutateMethod()(r)) and keep every
overridable route behindHandleCSRF.- State-changing routes need an explicit
.Methods(...)with POST (or
PUT/PATCH/DELETE).HandleCSRFnever checks GET/HEAD/OPTIONS, so a route
without.Methodsaccepts HEAD and OPTIONS without a token, and GET logout
or delete links are unprotected. TRACE now requires a token. See
Routes must set.Methods. HandleCSRFcaps form-token request bodies at 1 MiB (413), and the limit
carries into the handler (form.Bind,r.FormFile). Header-token and
streaming requests are not capped. For uploads, give the upload routes their
ownHandleCSRF(h, WithCSRFMaxBodyBytes(n))on a subrouter, take
HandleCSRFoff the root router, put the rest on anappsubrouter,
and move the middleware that ran afterHandleCSRFonto both. Every route
left on the root router runs without CSRF protection. See
Request body limit.
Proxies and hosts
SecureHeadersdistrustsX-Forwarded-Host, and HSTSpreloadis
opt-in. Behind a proxy that rewritesHost, add
WithSSLHost("www.example.com"), orWithTrustedHostHeaders("X-Forwarded-Host")
together withWithAllowedHosts(...)(neverWithTrustedHostHeadersalone).
Hosts outsideWithAllowedHostsget 400, including health checks that use an
IP. Preloaded domains addWithHSTSPreload(). Even without a proxy, pin
the host outside dev mode withWithAllowedHostsorWithSSLHost, as
examples/ssr-oidcnow does; otherwise the HTTPS redirect goes to whatever
Hostthe client sent. See
SecureHeaders options.serverEndpointis empty outside dev mode unless
TemplateConfig.ServerEndpointorAllowedHostsis set (a warning is logged
once). The newAllowedHostsfield breaks unkeyedTemplateConfig
struct literals at compile time; rewrite them with field names. See
serverEndpoint.response.Backredirects to/unless the referrer is same-host
http(s); userinfo is stripped. A proxy that rewritesHostmakes every
Backgo to/.RealHostFromRequestkeeps IPv6 brackets (https://[2001:db8::1]:8443),
and::1now counts as localhost (http://[::1]:8080). This also changes
the dev-modeserverEndpointfor a browser on[::1].
Cookies and sessions
- Session cookies are always
SecureandHttpOnly, andSameSite
defaults to Lax.Secure: !devModeno longer has any effect; pass
cookiestore.WithInsecureCookies()in local HTTP dev. Keep an explicit
SameSiteif you set one (Strictis kept). The defaults apply only at
New; later edits tosession.Optionsare not checked. See
Cookie defaults. - SameSite=Lax breaks cross-site POST callbacks (OIDC
form_post, SAML
POST binding). SetSameSite: http.SameSiteNoneModefor those apps.
SameSite=None forcesSecure, even withWithInsecureCookies(). - Split-value cookies are bound to their session.
_gbs-<key>cookies
from v1.0.0 or v1.0.1 are dropped once at upgrade (for example a stored ID token,
which may force a re-login). During a rolling deploy, a visitor who moves
from a v1.0.0/v1.0.1 instance back to a v1.1 instance loses split values
each time. v1.0.2 uses the same binding, so coming from v1.0.2 drops nothing.
The binding ID is stored under the reserved session key"_gbs_binding";
apps must not use that key. One session may split several keys, but two
named sessions on the same router must not split the same key. Deleting the
session (Options.MaxAge = -1) now also expires its split cookies. See
Split values. - Recommended, opt-in:
middleware.CheckSessionMaxAge(absolute session
lifetime). Install it afterRequireSessionand beforeHandleCSRF, and
reset the session (or callsession.StoreCreatedAt) at login. v1.0.x
cookies start their clock at the first v1.1 request. See
Absolute session lifetime.
Server
ServeHTTPHandlertimeouts:ReadTimeout5m andIdleTimeout120s.
NoWriteTimeout, so SSE and streaming responses keep working. Hijacked
connections (WebSockets) inherit the read deadline; clear it with
conn.SetReadDeadline(time.Time{}). UseServeHTTPwith your own
http.Serverfor other limits.
Secrets and keys
- Vault secrets read the latest version when
?version=is absent. Pin
?version=1only if you depended on v1. References with a URL scheme, host
or fragment are rejected. VaultSignis pinned to the signer's key
version,SigningKeyVersionsis newest first (was oldest first), and
key IDs with a non-numeric version (k@,k@abc) are rejected. - Azure
Encryptwith AAD returns an error.Decryptwith AAD still
works and logs a warning once.SigningKeyVersionsnow works, returns
VAULT/KEY/VERSIONIDs (not URLs) and omits disabled versions. Vault names
must match^[A-Za-z0-9-]{3,24}$. - Filesystem key versions must be decimal digits. Hand-placed non-numeric
version files are ignored byEncryptandSigningKeyVersions, and
Decryptrejects ciphertext that names them (invalid ciphertext: bad version). Versions fromCreateKeyVersionare unaffected. secretsCacher shared fetches keep the first caller's context values
but ignore every caller's cancellation and deadline. Each fetch runs with a
fixed 30s timeout. No caller can cancel it, including the first
caller, which runs the fetch; every caller waits up to 30s, so a handler
can overrun its own deadline. A provider that authorizes per caller through
context values must not be wrapped inWrapCacher.
Cache
cache.WriteThruLookupcoalesces per key: concurrent callers share the
owner's result and error (errors aren't cached); a panicking lookup gives
waiterscache.ErrLookupPanicked; TTLs overcache.MaxExpireAfter(100
years) returnErrInvalidDuration(message changed;errors.Isstill
works). Don't capture a request context inprimaryLookup; use
context.WithoutCancelplus a timeout.
Rendering
toJSONrenders the JSON value (HTML:template.JS, space-padded;
text: a string). Dropprintf "%s"/safeJS/atobworkarounds.RenderCSVContent-Dispositionisattachment; filename=…(space,
quoting, RFC 2231filename*for non-ASCII). Parse it with
mime.ParseMediaType.joinStrings/toSentencewith nil render""instead of a 500.
API shape
- Three function types gained variadic options (see
API changes). Every direct call compiles; code that stores
SecureHeaders,HandleCSRForcookiestore.Newin a variable, field or
parameter of the old func type must add the variadic parameter or wrap the
call in a closure.
Patterns copied from examples/ssr-oidc or the auth skill
- GET logout: see entry 2.
- OIDC flow state cleared in a
defer: session changes after the first response
byte are lost. Delete the state/nonce/verifier before checking anything or
writing the response. - State and nonce compared with
==/!=: usesubtle.ConstantTimeCompareand
reject empty values. - Authorization by an unverified email: require
email_verifiedto be the JSON
booleantrue, or key grants on the subject. - CSRF token not rotated at login: reset
session.Valuesor call
session.ClearCSRFTokenwhen privileges change. RenderJSONwitherr.Error()leaks error text; useRenderJSON500for
unexpected errors.
Rollback
Ciphertext and cookie formats are unchanged, and v1.0.x can decode v1.1
session cookies. If you must roll back, use v1.0.2: it carries the same split-cookie
binding and keeps split values. A downgrade to v1.0.0 or v1.0.1 also keeps
split values, but those releases join them without checking the binding, so
they are exposed to GHSA-fqhp-2jm8-w3vm again, and because they
rewrite split cookies without the binding, returning to v1.1 drops split
values once. v1.0.x ignores the created-at tracking that CheckSessionMaxAge
uses, and Azure VAULT/KEY/VERSION signing key IDs were never usable on v1.0.x.
Every release before v1.0.2 is vulnerable to all three advisories.
API changes
From apidiff (v1.0.1 → v1.1.0):
Incompatible (each only gains a trailing variadic parameter; every direct
call still compiles, but code that stores these in a variable of the old func
type does not):
cookiestore.New:func(EntropyFunc, *sessions.Options) sessions.Store→func(EntropyFunc, *sessions.Options, ...Option) sessions.Storemiddleware.HandleCSRF:func(*render.Renderer) mux.MiddlewareFunc→func(*render.Renderer, ...CSRFOption) mux.MiddlewareFuncmiddleware.SecureHeaders:func(bool, ServerType) mux.MiddlewareFunc→func(bool, ServerType, ...SecureOption) mux.MiddlewareFunc
Added:
cache:ErrLookupPanicked,MaxExpireAftercookiestore:Option,WithInsecureCookiesmiddleware:CSRFOption,CheckSessionMaxAge,DefaultCSRFMaxBodyBytes,SecureOption,TemplateConfig.AllowedHosts,WithAllowedHosts,WithCSRFMaxBodyBytes,WithHSTSPreload,WithSSLHost,WithTrustedHostHeaderssession:CreatedAt,StoreCreatedAt- (internal packages only:
internal/azureauth.ValidateVaultName,VaultURL;internal/util.RandomToken)
The split-cookie binding adds no exported API; it uses the reserved session key
"_gbs_binding". Nothing is deprecated.
Upgrade
go get github.com/mikehelmick/go-bananas@v1.1.0
go mod tidy && go build ./... && go vet ./... && go test ./...
go run golang.org/x/vuln/cmd/govulncheck@latest ./...