Skip to content

User-Agent header missing in Release builds#283

Merged
AlexNachbaur merged 2 commits into
masterfrom
fix/254-user-agent-release-builds
Jul 2, 2026
Merged

User-Agent header missing in Release builds#283
AlexNachbaur merged 2 commits into
masterfrom
fix/254-user-agent-release-builds

Conversation

@AlexNachbaur

@AlexNachbaur AlexNachbaur commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

SDKVersion.userAgent is populated as a side effect of evaluating the lazy static let registration in each Version+*.swift. Every dereference site was spelled assert(SDKVersion.X != nil) — but Swift's assert(_:) takes its condition as @autoclosure, which the optimizer strips entirely in -O (Release) builds. In Release/TestFlight builds the lazies never fire, SDKVersion._userAgent stays the empty string, and every outgoing SDK request goes out with an empty User-Agent header.

This reproduces exactly as reported: present in Debug, missing in Release. For at least one customer (MGM Resorts), the header-less traffic is being flagged as bot activity by their WAF.

Replaces the 19 assert(SDKVersion.X != nil) triggers across 13 files with _ = SDKVersion.X, so the lazy registration fires unconditionally regardless of build configuration. Same registration mechanism — only the trigger moves out of an @autoclosure.

Adds Tests/AuthFoundationTests/SDKVersionRegistrationTests.swift to pin the contract. Verified locally: fails on unmodified master under swift test -c release, passes after this change. Full suite (395 tests) passes in both Debug and Release after the fix.

Credit

This is a cherry-pick of the fix and diagnosis from @RicardoKoch's #277, with a follow-up commit trimming the new test's doc comment to match this repo's style. Opening as a fresh PR against current master (superseding #277) since that PR's CI never ran and it needed review from an Okta maintainer.

Fixes #254.

RicardoKoch and others added 2 commits July 2, 2026 11:50
SDKVersion.userAgent is populated as a side effect of evaluating the
lazy 'static let' registration in each Version+*.swift. Every dereference
site is currently spelled 'assert(SDKVersion.X != nil)' — but Swift's
assert(_:) takes its condition as @autoclosure, which the optimizer
strips in -O builds. In Release builds the lazies never fire,
SDKVersion._userAgent stays the empty string, and every outgoing request
goes out with an empty User-Agent header.

Replace the 19 'assert(SDKVersion.X != nil)' triggers across 13 files
with '_ = SDKVersion.X' so the lazy registration fires regardless of
build configuration. Same registration mechanism — only the trigger
moves out of an @autoclosure.

Adds Tests/AuthFoundationTests/SDKVersionRegistrationTests.swift to pin
the contract. Verified to fail in 'swift test -c release' before this
change and pass after.
@AlexNachbaur AlexNachbaur changed the title Fix #254 — User-Agent header missing in Release builds User-Agent header missing in Release builds Jul 2, 2026
@AlexNachbaur
AlexNachbaur merged commit 34932b9 into master Jul 2, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User-Agent header missing in Release builds

3 participants