Skip to content

v1.1.0

Choose a tag to compare

@mikehelmick mikehelmick released this 16 Nov 04:12
82e78ca

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

  • render joinStrings/toSentence panicked on a nil value, so
    {{joinStrings .missing ", "}} returned a 500. They now render "".
  • response.RealHostFromRequest dropped IPv6 brackets
    (https://2001:db8::1:8443); it now uses net.JoinHostPort and returns
    https://[2001:db8::1]:8443. ::1 (with or without brackets) now counts as
    localhost and gets http: http://[::1]:8080, where v1.0.x gave
    https://::1:8080.

Other fixes

  • keys.Filesystem.Encrypt picks the latest version numerically (it compared as
    text, so 9 beat 10), and SigningKeyVersions skips stray non-numeric files
    instead of failing.
  • keys/azure.SigningKeyVersions works (it failed on every call), returns
    VAULT/KEY/VERSION IDs, sorts newest first, and omits disabled versions.
  • keys/vault.SigningKeyVersions sorts newest first, and parseKeyID accepts
    the name/N form that KeyID() returns.
  • secrets Cacher 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

  1. MutateMethod ignores _method in 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. Under r.Use it only changes what later handlers see, not which
    route matches. Wrap the router (middleware.MutateMethod()(r)) and keep every
    overridable route behind HandleCSRF.
  2. State-changing routes need an explicit .Methods(...) with POST (or
    PUT/PATCH/DELETE). HandleCSRF never checks GET/HEAD/OPTIONS, so a route
    without .Methods accepts HEAD and OPTIONS without a token, and GET logout
    or delete links are unprotected. TRACE now requires a token. See
    Routes must set .Methods.
  3. HandleCSRF caps 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
    own HandleCSRF(h, WithCSRFMaxBodyBytes(n)) on a subrouter, take
    HandleCSRF off the root router, put the rest on an app subrouter,
    and move the middleware that ran after HandleCSRF onto both. Every route
    left on the root router runs without CSRF protection.
    See
    Request body limit.

Proxies and hosts

  1. SecureHeaders distrusts X-Forwarded-Host, and HSTS preload is
    opt-in.
    Behind a proxy that rewrites Host, add
    WithSSLHost("www.example.com"), or WithTrustedHostHeaders("X-Forwarded-Host")
    together with WithAllowedHosts(...) (never WithTrustedHostHeaders alone).
    Hosts outside WithAllowedHosts get 400, including health checks that use an
    IP. Preloaded domains add WithHSTSPreload(). Even without a proxy, pin
    the host
    outside dev mode with WithAllowedHosts or WithSSLHost, as
    examples/ssr-oidc now does; otherwise the HTTPS redirect goes to whatever
    Host the client sent. See
    SecureHeaders options.
  2. serverEndpoint is empty outside dev mode unless
    TemplateConfig.ServerEndpoint or AllowedHosts is set (a warning is logged
    once). The new AllowedHosts field breaks unkeyed TemplateConfig
    struct literals at compile time; rewrite them with field names. See
    serverEndpoint.
  3. response.Back redirects to / unless the referrer is same-host
    http(s); userinfo is stripped. A proxy that rewrites Host makes every
    Back go to /.
  4. RealHostFromRequest keeps IPv6 brackets (https://[2001:db8::1]:8443),
    and ::1 now counts as localhost (http://[::1]:8080). This also changes
    the dev-mode serverEndpoint for a browser on [::1].

Cookies and sessions

  1. Session cookies are always Secure and HttpOnly, and SameSite
    defaults to Lax. Secure: !devMode no longer has any effect; pass
    cookiestore.WithInsecureCookies() in local HTTP dev. Keep an explicit
    SameSite if you set one (Strict is kept). The defaults apply only at
    New; later edits to session.Options are not checked. See
    Cookie defaults.
  2. SameSite=Lax breaks cross-site POST callbacks (OIDC form_post, SAML
    POST binding). Set SameSite: http.SameSiteNoneMode for those apps.
    SameSite=None forces Secure, even with WithInsecureCookies().
  3. 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.
  4. Recommended, opt-in: middleware.CheckSessionMaxAge (absolute session
    lifetime). Install it after RequireSession and before HandleCSRF, and
    reset the session (or call session.StoreCreatedAt) at login. v1.0.x
    cookies start their clock at the first v1.1 request. See
    Absolute session lifetime.

Server

  1. ServeHTTPHandler timeouts: ReadTimeout 5m and IdleTimeout 120s.
    No WriteTimeout, so SSE and streaming responses keep working. Hijacked
    connections (WebSockets) inherit the read deadline; clear it with
    conn.SetReadDeadline(time.Time{}). Use ServeHTTP with your own
    http.Server for other limits.

Secrets and keys

  1. Vault secrets read the latest version when ?version= is absent. Pin
    ?version=1 only if you depended on v1. References with a URL scheme, host
    or fragment are rejected. Vault Sign is pinned to the signer's key
    version, SigningKeyVersions is newest first (was oldest first), and
    key IDs with a non-numeric version (k@, k@abc) are rejected.
  2. Azure Encrypt with AAD returns an error. Decrypt with AAD still
    works and logs a warning once. SigningKeyVersions now works, returns
    VAULT/KEY/VERSION IDs (not URLs) and omits disabled versions. Vault names
    must match ^[A-Za-z0-9-]{3,24}$.
  3. Filesystem key versions must be decimal digits. Hand-placed non-numeric
    version files are ignored by Encrypt and SigningKeyVersions, and
    Decrypt rejects ciphertext that names them (invalid ciphertext: bad version). Versions from CreateKeyVersion are unaffected.
  4. secrets Cacher 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 in WrapCacher.

Cache

  1. cache.WriteThruLookup coalesces per key: concurrent callers share the
    owner's result and error (errors aren't cached); a panicking lookup gives
    waiters cache.ErrLookupPanicked; TTLs over cache.MaxExpireAfter (100
    years) return ErrInvalidDuration (message changed; errors.Is still
    works). Don't capture a request context in primaryLookup; use
    context.WithoutCancel plus a timeout.

Rendering

  1. toJSON renders the JSON value (HTML: template.JS, space-padded;
    text: a string). Drop printf "%s"/safeJS/atob workarounds.
  2. RenderCSV Content-Disposition is attachment; filename=… (space,
    quoting, RFC 2231 filename* for non-ASCII). Parse it with
    mime.ParseMediaType.
  3. joinStrings/toSentence with nil render "" instead of a 500.

API shape

  1. Three function types gained variadic options (see
    API changes). Every direct call compiles; code that stores
    SecureHeaders, HandleCSRF or cookiestore.New in 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 ==/!=: use subtle.ConstantTimeCompare and
    reject empty values.
  • Authorization by an unverified email: require email_verified to be the JSON
    boolean true, or key grants on the subject.
  • CSRF token not rotated at login: reset session.Values or call
    session.ClearCSRFToken when privileges change.
  • RenderJSON with err.Error() leaks error text; use RenderJSON500 for
    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.Store
  • middleware.HandleCSRF: func(*render.Renderer) mux.MiddlewareFunc → func(*render.Renderer, ...CSRFOption) mux.MiddlewareFunc
  • middleware.SecureHeaders: func(bool, ServerType) mux.MiddlewareFunc → func(bool, ServerType, ...SecureOption) mux.MiddlewareFunc

Added:

  • cache: ErrLookupPanicked, MaxExpireAfter
  • cookiestore: Option, WithInsecureCookies
  • middleware: CSRFOption, CheckSessionMaxAge, DefaultCSRFMaxBodyBytes, SecureOption, TemplateConfig.AllowedHosts, WithAllowedHosts, WithCSRFMaxBodyBytes, WithHSTSPreload, WithSSLHost, WithTrustedHostHeaders
  • session: 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 ./...