preliminary auth review 2 - #49
Draft
jumpy-cat wants to merge 1 commit into
Draft
Conversation
Authentication: - Add SAML strategy (src/auth/saml.ts) to authenticate users via UMich Shibboleth, supporting both test and production IdP endpoints. SAML disables gracefully if certificate files are missing so the server can still start in development. - Add auth routes (src/routes/auth.ts) for login redirect, SAML callback, logout with Single Logout, session introspection (/me), and SP metadata serving for IdP registration. - Back sessions with MongoDB via connect-mongo so sessions survive server restarts and are production-ready. Cookies are httpOnly, secure in production, and sameSite=lax. Middleware: - Add requireAuth to gate user-specific endpoints behind a valid Shibboleth session, returning 401 for unauthenticated requests. - Add requireAdmin to gate future usage-data endpoints behind an "admin" role check on InternalAccount, returning 403 for non-admins. This replaces the separate DevAccount model — admin users log in via Shibboleth like everyone else and are promoted in MongoDB. User data routes: - Rewrite all CRUD endpoints to use implicit ownership (Approach A): no :accountId in URLs, all queries scoped to req.user.accountId. This eliminates authorization bypass bugs where a missing ownership check could expose another user's data. - Remove POST /account since accounts are auto-provisioned on first SAML login via upsert in the verify callback. - Validate all write request bodies with Zod schemas. Cleanup: - Remove DevAccount model, dev routes, and requireDev middleware. Admin access is handled by the roles array on InternalAccount. - Remove JWT_SECRET and DEV_ADMIN_KEY from .env_example. - Add SAML and session environment variables to .env_example with setup instructions for certificate files.
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.
Authentication:
Middleware:
User data routes:
Cleanup: