- Branch reviewed:
fix/issue-4-auth-guard - Command:
git diff main...fix/issue-4-auth-guard --stat - Result:
scaffold/spec-site/src/pages/LoginPage.vue(new)scaffold/spec-site/src/router.ts(modified)
- ✅ Constraint check passed: only
scaffold/spec-site/files changed.
-
Diff stat checked
- ✅ Done
-
beforeEachguard exists in router config- ✅ Present in
scaffold/spec-site/src/router.ts - Logic includes static mode bypass, public route allow, token check, redirect to
/login
- ✅ Present in
-
Public routes whitelisted (
/login, landing)- ✅
/loginhasmeta: { public: true } - ✅
/hasmeta: { public: true }
- ✅
-
Protected routes redirect to
/loginwhen no token- ✅ In API mode, any route without
meta.publicrequires localStorage token (spec-auth-token) - ✅ Missing token redirects to
/login?redirect=<originalPath>
- ✅ In API mode, any route without
-
Login page/component exists
- ✅
LoginPage.vueadded and wired via router - Includes token input + submit + auto-login flow
- ✅
- Where:
LoginPage.vue - Code pattern:
const redirectTo = (route.query.redirect as string) || '/'router.replace(redirectTo)
- Risk: If
redirectaccepts arbitrary string values, this can become an open-redirect vector or at least allow unintended navigation targets. - Suggestion: Validate
redirectToto allow only internal app paths (e.g., starts with/and not//, no protocol).
- Where:
router.tsglobalbeforeEach - Code pattern:
const token = localStorage.getItem(AUTH_STORAGE_KEY); if (token) return true - Risk: Expired/revoked/garbage token still unlocks protected routes at router level; user sees protected shell until downstream API failures occur.
- Suggestion: Add lightweight auth state validation on app boot/first navigation (or central
useAuthstate), and redirect to login when validation fails.
- Where:
router.ts(/dashboardsetsmeta: { ..., requiresAuth: true }) - Risk: Inconsistent authorization model (some routes use
requiresAuth, guard ignores it and enforces auth by!public). Future contributors may misconfigure routes due to mixed semantics. - Suggestion: Standardize one pattern:
- Either auth by default except
public, or - enforce only when
requiresAuthis true. Document and apply consistently.
- Either auth by default except
- Where:
LoginPage.vue+useAuth.ts - Risk: Visiting
/loginwith a stored token always callstryAutoLogin()→login(stored)→/api/auth/verify. This may add unnecessary auth traffic and slow UX on unstable networks. - Suggestion: Cache recent verification status or use in-memory authenticated state first, with periodic/background revalidation.
REQUEST_CHANGES
Auth guard and login wiring are mostly correct and functional, but I recommend changes before approval due to security/robustness concerns (especially redirect sanitization and token-validation behavior at route entry).