feat(assessment): record capture hints and keep one window per attempt

This commit is contained in:
shira committed 2026-10-11 13:16:52 +03:00
1 parent c975a0d506
commit bb917bf62e
108 files changed
+6649 -139

No files matched your search

@@ -12,10 +12,15 @@ const SessionCookieName = "__Host-lincodex_session"
type sessionRequestMetadataKey struct{}
// maxUserAgentBytes bounds the User-Agent that is kept for the request. A
// browser sends a few hundred bytes; the rest is not a browser.
const maxUserAgentBytes = 512
type sessionRequestMetadata struct {
origin string
originValid bool
incomingToken domain.SecretToken
userAgent string
}
// SessionRequestMetadata records the browser Origin and an optional incoming
@@ -24,7 +29,7 @@ type sessionRequestMetadata struct {
func SessionRequestMetadata() func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
metadata := sessionRequestMetadata{}
metadata := sessionRequestMetadata{userAgent: boundedUserAgent(r.Header.Get("User-Agent"))}
origins := r.Header.Values("Origin")
if len(origins) == 1 {
metadata.origin = origins[0]
@@ -55,6 +60,21 @@ func RequestOrigin(ctx context.Context) (string, bool) {
return metadata.origin, ok && metadata.originValid
}
// RequestUserAgent returns the User-Agent of the request, cut to a safe length,
// or an empty string when it had none. It exists to be hashed with a key into a
// signal of the attempt; callers never store or log it.
func RequestUserAgent(ctx context.Context) string {
metadata, _ := ctx.Value(sessionRequestMetadataKey{}).(sessionRequestMetadata)
return metadata.userAgent
}
func boundedUserAgent(value string) string {
if len(value) > maxUserAgentBytes {
return value[:maxUserAgentBytes]
}
return value
}
// IncomingSessionToken returns a parsed token from exactly one session cookie.
// The zero value means missing, malformed, or duplicated input.
func IncomingSessionToken(ctx context.Context) domain.SecretToken {