Skip to content

fix(auth): remove JS-readable token persistence and use HttpOnly session cookie#27

Open
KinshukSS2 wants to merge 1 commit intoistSOS:mainfrom
KinshukSS2:fix/security-problem-004-auth-token-exposure
Open

fix(auth): remove JS-readable token persistence and use HttpOnly session cookie#27
KinshukSS2 wants to merge 1 commit intoistSOS:mainfrom
KinshukSS2:fix/security-problem-004-auth-token-exposure

Conversation

@KinshukSS2
Copy link
Copy Markdown

@KinshukSS2 KinshukSS2 commented Apr 14, 2026

Summary

This PR hardens authentication token handling by removing browser-script-readable token persistence and moving session token management to server-side HttpOnly cookies.

What changed

  • Removed token persistence in browser localStorage.
  • Removed client-side token cookie writes (httpOnly: false pattern).
  • Added server-side auth cookie lifecycle (login, logout, refresh) using HttpOnly cookie flags.
  • Refactored client auth context to session-state semantics (authenticated, username, loading) without exposing bearer token to browser code paths.
  • Updated service auth-header resolution to read token server-side from cookies when explicit token is absent.

Security outcome

  • localStorage.getItem('token') no longer returns a bearer token.
  • Token cookie is now server-managed and HttpOnly.
  • Client-side scripts can no longer directly read bearer token values.

Files touched

  • ui/context/AuthContext.tsx
  • ui/features/auth/components/Login.tsx
  • ui/components/layout/Navbar.tsx
  • ui/app/Home.tsx
  • ui/features/forms/components/FormModal.tsx
  • ui/services/auth.ts
  • ui/services/fetch.ts
  • ui/services/things.ts
  • ui/services/locations.ts
  • ui/services/sensors.ts
  • ui/services/datastreams.ts
  • ui/services/observedProperties.ts
  • SECURITY_PROBLEM_004_auth_token_exposure.md

Validation

  • Build succeeds: npm run build in ui.
  • Security grep confirms no client token storage/cookie write patterns remain under ui.

fix #28

@KinshukSS2 KinshukSS2 force-pushed the fix/security-problem-004-auth-token-exposure branch from 63cfe79 to b29c220 Compare April 14, 2026 22:36
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.

Auth token is exposed to client-side scripts (security)

1 participant