refactor: replace Bearer token auth with HttpOnly cookies #84
Reference in New Issue
Block a user
Delete Branch "feature/cookie-auth-refactor"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Major auth refactor replacing Bearer token authentication with HttpOnly cookie-based auth, removing the registration endpoint, and adding the PASS IRC command for password management.
Changes
Removed
POST /api/v1/registerendpoint (no separate registration path)RegisterUserDB methodAuthorization: Bearerheader parsingtokenfield from all JSON response bodiesTokenfield from CLISessionResponsetypeAdded
neoirc_authHttpOnly cookie set on session creation and loginPOST /api/v1/messages {"command":"PASS","body":["password"]}(minimum 8 characters)SetPasswordDB method (bcrypt hashing)setAuthCookie(),clearAuthCookie()AllowCredentials: truewith origin reflection functionAuth Flow
POST /api/v1/session {"nick":"alice"}→ setsneoirc_authcookie, returns{"id":1,"nick":"alice"}POST /api/v1/messages {"command":"PASS","body":["s3cret"]}→ sets password for multi-clientPOST /api/v1/login {"nick":"alice","password":"s3cret"}→ setsneoirc_authcookieTests
TestPassCommand,TestPassCommandShortPassword,TestPassCommandEmpty,TestSessionCookieREADME
CI
docker build .passes (format check, lint, all tests, build)closes #83
Review: PR #84 — Auth Refactor (Bearer tokens → HttpOnly cookies)
Verdict: PASS ✅
Verification Points
setAuthCookie()correctly sets all three.Securechecks bothrequest.TLSandX-Forwarded-Protofor reverse proxy support.clearAuthCookie()mirrors the same properties withMaxAge: -1.tokenin JSON responseshandleCreateSessionandhandleLoginboth return only{"id", "nick"}.SessionResponsetype in CLI also has onlyID+Nick. TestTestSessionCookieexplicitly asserts notokenkey exists in the JSON body.handlePassvalidates empty/missing body → ERR_NEEDMOREPARAMS (461), short password (<8) → ERR_NEEDMOREPARAMS, then callsdatabase.SetPassword()which usesbcrypt.GenerateFromPasswordat default cost. Three tests cover this:TestPassCommand,TestPassCommandShortPassword,TestPassCommandEmpty./registerroute gone fromroutes.go.HandleRegisterfunction removed.RegisterUserDB method removed.grepconfirms no register references remain (only IRC numerics).grep -rn "Bearer|Authorization" --include="*.go"returns nothing.authSession()now reads fromrequest.Cookie(authCookieName).Authorizationremoved from CORSAllowedHeaders.AllowCredentials: trueAllowOriginFunc(reflects origin, not*),AllowCredentials: true.handleQuitandHandleLogoutcallclearAuthCookie()which setsMaxAge: -1.Client.Tokenfield removed.NewClient()createscookiejar.New(nil)and setsJaronHTTPClient.PollMessagesshares the jar.do()no longer sets Authorization header.-c/-b cookies.txt), Python/JS examples, security model, roadmap.doRequestAuthuses cookies.createSessionextracts cookie from response. Register tests replaced with PASS command tests. NewTestSessionCookievalidates HttpOnly, SameSite, and no-token-in-body.Build Result
Code Quality Notes
Positive:
setAuthCookie/clearAuthCookie) reused consistently across session creation, login, logout, and QUITinitChannelState()Minor Documentation Nits (non-blocking)
A few stale
tokenreferences survived in README sections adjacent to or near changed lines:token_a, token_b, token_c— could becookie_aetc.None affect functionality. Worth a follow-up cleanup.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.