Repository navigation
fix(ui): trim the username on self-hosted sign-in - #718
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
7fc489a to
a880fbc
Compare
The sign-in form checked username.trim() for emptiness but posted the raw value, and the login route compared it as typed, so a username with a stray leading or trailing space was rejected even though the form accepted it. Trim it in the form before sending, and in the route before comparing. The password is left untouched. Signed-off-by: Emre Öcel <73295089+emreocell@users.noreply.github.com>
… credentials still fail The route tests from #719, which fixed #717 in the same way as #718 at the same time. The fix itself and the form test were already in #718, so this commit carries the tests #718 doesn't have: the session cookie a padded username gets is valid and Secure, and a wrong password, another user or a blank username still get 401. Cherry-picked from #719 (9f725fc) unchanged, as route.session.test.ts.
a880fbc to
23a653b
Compare
|
Thank you @emreocell, and @FFXFF1 for #719. You both found and fixed #717 the same way, 20 seconds apart, so we're landing the two as one PR. That way the fix goes in once and both of you are credited as authors on main. This PR now has two commits:
It will land with Rebase and merge, so each commit stays under its own author and you both count as contributors. All 17 sign-in tests pass. |
richard-epsilla
left a comment
There was a problem hiding this comment.
Two authors, one fix: @emreocell's fix and tests, and @FFXFF1's session tests from #719. Sign-in tests 17/17; all checks green.
The bug
On the self-hosted sign-in, a username typed or pasted with a leading or trailing space (
alice) and the correct password is rejected with "Incorrect username or password." The form accepts the input: it checksusername.trim()for an empty field, but then posts the rawusername. The login route compares the value as received, with an exact comparison.Expected behavior
Surrounding whitespace in the username is ignored, the way the form's own empty-field check already treats it, so
alicesigns in asalice.The fix
SelfHostLogin.tsx: postusername.trim().api/selfhost/login/route.ts: trim the username beforecredentialsValid, so any other client gets the same behavior. The password is never trimmed (it may legitimately start or end with a space).This also matches
profile/route.ts, which already trims the username when it stores new credentials.Verification
From
ui/(Node 24, Windows):SelfHostLogin.test.tsx: typingadminposts{"username":"admin","password":" right "}.src/app/api/selfhost/login/route.test.ts(credentials fromHR_AUTH_USER/HR_AUTH_PASSWORD):alice,aliceand a tab/newline-wrappedaliceall sign in (200 + session cookie); a wrong password and a password with added spaces still return 401.npx jest src/components/SelfHostLogin.test.tsx src/app/api/selfhost/login/route.test.ts).npx tsc --noEmit: clean.npx jest: 151 suites pass, 3 fail (hrui/start/open.test.ts,hrui/setup/agent-chat-css.test.ts,hrui/memories/tree/MemoryTree.test.tsx, 7 tests); the same 3 suites with the same 7 failing tests fail on an untouchedmaincheckout here, so they are unrelated.npm run build, the gateway tests, and the container-level self-hosted flow (no Docker here).Fixes #717