fix(web): prevent crash when User-Agent header is missing#1309
Merged
Conversation
When anonymous access is enabled, session-less requests fall through to
the (app) layout's mobile-detection check instead of redirecting to
/login. Requests without a User-Agent header (e.g. proxy/health-check
probes) caused getSelectorsByUserAgent('') to return undefined, throwing
a TypeError on the isMobile destructure and crashing the web UI.
Only call getSelectorsByUserAgent when a non-empty User-Agent is present.
Fixes #1308
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe ChangesUser-Agent Null Safety Fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Excellent Merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes SOU-1328
Fixes #1308
Problem
Enabling anonymous access made the web UI unavailable, with the Docker logs showing a recurring
No valid user agent string was providedwarning followed by aTypeErrordestructuringisMobilefromundefined.Root cause: In
packages/web/src/app/(app)/layout.tsx, the mobile-detection check callsgetSelectorsByUserAgent(userAgent ?? '').react-device-detectreturnsundefined(not an object) for an empty string, so destructuring{ isMobile }throws.Why anonymous access is the trigger: With anonymous access disabled, session-less requests are redirected to
/loginearlier in the layout and never reach this line. With anonymous access enabled, they fall through to the mobile check. Requests that omit theUser-Agentheader (proxy/health-check probes, e.g. HAProxyoption httpchk) then crash the root(app)layout, taking down the whole UI. These recurring probes are what produced the repeating error in the logs.Fix
Only call
getSelectorsByUserAgentwhen a non-emptyUser-Agentis present; otherwise treat the client as non-mobile.Reproduction
Against a single-tenant instance with anonymous access enabled, send a request to the app root with an empty/missing User-Agent:
Before:
500(crashed layout). After: renders normally. With anonymous access disabled, the same request 307-redirects to/login(unchanged).🤖 Generated with Claude Code
Summary by CodeRabbit