#13292·authelia

Passkey login fails with "challenge session data is not present" after restart: memory session provider key aliases request buffer

Author: AranshCreated Sep 28, 2026Updated Sep 29, 2026
Labelspriority/4/normaltype/bug/unconfirmedstatus/needs-triage

Version

v4.39.28

Deployment Method

Docker

Reverse Proxy

NGINX

Reverse Proxy Version

1.31.6

Description

**Disclaimer - While I am experiencing this issue for a while, I’ve used Claude (Opus 5.5) to debug this and come to the upcoming conclusions

With the default in-memory session provider, WebAuthn passkey login intermittently fails on the first attempt with challenge session data is not present. A retry works.

Trigger: the browser presents a session cookie whose ID is unknown to the store (a stale cookie after Authelia/host restart). Reproduced on a real deployment: after restart, a private tab (no cookie) succeeds first try, while a normal tab (stale cookie) fails first try.

Root cause (as far as I can tell from reading the code): internal/session/memory/provider.go:

go
func (p *Provider) getSessionKey(sessionID []byte) string {
	return strconv.B2S(sessionID) // gotils: unsafe.String, zero-copy
}

Save stores that string as a sync.Map key. When the ID comes from the request cookie (fasthttp/session getSessionID → ctx.Request.Header.Cookie(name)), the bytes belong to fasthttp's reusable header/cookie buffer. The stored key therefore mutates when that buffer is reused, and later lookups for the correct ID miss. Newly generated IDs are separate allocations, and login regenerates the ID, so it only bites pre-login sessions created from a client-supplied ID, i.e. exactly the passkey GET (store challenge) → POST (read challenge) window.

The same code exists upstream in fasthttp/session providers/memory. The Redis provider is unaffected because it builds a copied key.

Reproduction

Minimal program (Authelia's internal/session/memory copied as package memory, fasthttp/session v2.5.9):

go
// Repro: Authelia internal/session/memory uses strconv.B2S (zero-copy) for the map key.
// A client-supplied session ID (cookie value) aliases fasthttp's reusable cookie buffer,
// so the stored key mutates when a later request reuses that buffer.
package main

import (
	"fmt"
	"io"
	"net"
	"net/http"

	"github.com/fasthttp/session/v2"
	"github.com/valyala/fasthttp"

	"repro/memory" // copy of authelia/internal/session/memory
)

func main() {
	prov, _ := memory.New(memory.Config{})
	cfg := session.NewDefaultConfig()
	cfg.CookieName, cfg.Secure = "authelia_session", false
	sess := session.New(cfg)
	_ = sess.SetProvider(prov)

	ln, _ := net.Listen("tcp", "127.0.0.1:0")
	go fasthttp.Serve(ln, func(ctx *fasthttp.RequestCtx) {
		store, _ := sess.Get(ctx)
		if string(ctx.Path()) == "/set" { // like FirstFactorPasskeyGET
			store.Set("webauthn", "challenge")
			_ = sess.Save(ctx, store)
			return
		}
		if store.Get("webauthn") == nil { // like FirstFactorPasskeyPOST
			fmt.Fprint(ctx, "MISSING")
		} else {
			fmt.Fprint(ctx, "PRESENT")
		}
	})

	c := &http.Client{Transport: &http.Transport{MaxConnsPerHost: 1}} // single keep-alive conn
	req := func(path, cookie string) string {
		r, _ := http.NewRequest("GET", "http://"+ln.Addr().String()+path, nil)
		r.Header.Set("Cookie", cookie)
		resp, err := c.Do(r)
		if err != nil {
			return err.Error()
		}
		defer resp.Body.Close()
		b, _ := io.ReadAll(resp.Body)
		return string(b)
	}

	// Stale session ID: unknown to the store (e.g. after an Authelia restart).
	req("/set", "authelia_session=STALEbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
	// Same session cookie, different position in the Cookie header.
	fmt.Println("result:", req("/get", "x=1; authelia_session=STALEbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
}

Output: result: MISSING. Dumping the map afterwards shows the stored key changed from STALEbbbb… to 1TALEbbbb… (the first byte was overwritten by the other cookie's value). With getSessionKey returning string(sessionID): result: PRESENT.

Real deployment:

  1. Log in normally (memory session provider), keeping the cookie.
  2. Restart Authelia/host.
  3. Passkey login in the same browser → first attempt fails; private tab → succeeds.

Expectations

The session entry stored for a client-supplied session ID remains retrievable; the passkey challenge saved by GET /api/firstfactor/passkey is found by the following POST.

Suggested fix: copy the key on write (string(sessionID) in getSessionKey, or at least in Save/Regenerate).

Configuration (Authelia)

yaml
Default memory session provider (no `session.redis`), `webauthn.enable_passkey_login: true`.

Build Information

bash
Last Tag: v4.39.28
State: tagged clean
Branch: v4.39.28
Commit: 8da42b2348b0351c6284a2940a9c5eec3d4cd3fd
Build Number: 59054
Build OS: linux
Build Arch: arm64
Build Compiler: gc
Build Date: Thu, 17 Sep 2026 22:09:13 +1000
Development: false
Extra: 

Go:
    Version: go1.27.1
    Module Path: github.com/authelia/authelia/v4
    Executable Path: github.com/authelia/authelia/v4/cmd/authelia

Logs (Authelia)

bash
level=trace msg="Replied (status=200)" method=GET path=/api/firstfactor/passkey
level=error msg="Error occurred validating a WebAuthn passkey authentication challenge: error occurred retrieving the user session data" error="challenge session data is not present" method=POST path=/api/firstfactor/passkey
level=error msg="Unsuccessful Passkey authentication attempt by user ''" method=POST path=/api/firstfactor/passkey

Logs (Proxy / Application)

bash

Documentation

No response

Generative AI

Yes

Pre-Submission Checklist

  • I agree to follow the Code of Conduct

  • This is a bug report and not a support request

  • I have read the security policy and this bug report is not a security issue or security related issue

  • I have either included the complete configuration file or I am sure it's unrelated to the configuration

  • I have either included the complete debug / trace logs or the output of the build-info command if the logs are not relevant

  • I have provided all of the required information in full with the only alteration being reasonable sanitization in accordance with the Troubleshooting Sanitization reference guide

  • I have checked for related proxy or application logs and included them if available

  • I have checked for related issues and checked the documentation