Fix email app auth and send routes#7346
Conversation
Greptile SummaryThis PR mounts the email app OAuth routes under
Confidence Score: 2/5Not safe to merge as-is — two auth/security concerns must be addressed before the email send path is exposed publicly. The PR activates two previously unreachable code paths. The POST /api/email/send and POST /api/email/draft endpoints now resolve their app.locals dependencies but still accept a plain userId from the request body with no proof of ownership, allowing any caller to send email on behalf of any known Omi user. The OAuth callback, now mounted at /api/auth/callback, includes the JWT in the redirect URL where it will be recorded in browser history and server logs. plugins/apps-js/server.js (authorization gap activated by app.locals wiring) and plugins/apps-js/email/src/routes/auth.js (JWT-in-URL pattern now reachable).
|
| Filename | Overview |
|---|---|
| plugins/apps-js/server.js | Mounts auth router and wires app.locals; activates previously non-functional email endpoints that accept userId from request body without token-based authorization. |
Sequence Diagram
sequenceDiagram
participant Client
participant Server as Express Server
participant AuthRouter as /api/auth (authRouter)
participant EmailRouter as /api/email (emailRouter)
participant AppLocals as app.locals
participant Supabase
participant Gmail
Note over Server: server.js wires app.locals on startup
Server->>AppLocals: "locals.getAuthenticatedUser = getAuthenticatedUser"
Server->>AppLocals: "locals.sendEmail = sendEmailWithGmail wrapper"
Client->>AuthRouter: GET /api/auth/login/:omiuid
AuthRouter->>Supabase: Store state in Redis
AuthRouter-->>Client: Redirect to Google OAuth
Client->>AuthRouter: "GET /api/auth/callback?code=...&state=..."
AuthRouter->>Supabase: Validate state, upsert user
AuthRouter-->>Client: Redirect with JWT token in URL + httpOnly cookie
Client->>EmailRouter: "POST /api/email/send {userId, recipientEmail, ...}"
EmailRouter->>AppLocals: req.app.locals.getAuthenticatedUser(userId)
AppLocals->>Supabase: Lookup user by omiuid
Supabase-->>AppLocals: user record with Gmail tokens
AppLocals-->>EmailRouter: user
EmailRouter->>AppLocals: req.app.locals.sendEmail(...)
AppLocals->>Gmail: gmail.users.messages.send
Gmail-->>AppLocals: message id
AppLocals-->>EmailRouter: result
EmailRouter-->>Client: 200 OK
Reviews (1): Last reviewed commit: "Fix email app auth and send routes" | Re-trigger Greptile
| return sendEmailWithGmail(recipientEmail, subject, content, user, options); | ||
| }; | ||
|
|
||
| // Rate limiting middleware |
There was a problem hiding this comment.
No authorization on send/draft endpoints
getAuthenticatedUser(userId) performs a plain Supabase lookup — it confirms the user exists but does not verify that the caller is that user. Now that app.locals is wired up, POST /api/email/send and POST /api/email/draft are fully functional. Any caller who supplies a valid Omi UID in the request body (userId) will be granted access to that user's Gmail credentials and can send email on their behalf. There is no Bearer token, API key, HMAC signature, or any other proof of ownership checked on these two endpoints.
| app.locals.sendEmail = (recipientEmail, subject, content, user, options = {}) => { | ||
| return sendEmailWithGmail(recipientEmail, subject, content, user, options); | ||
| }; |
There was a problem hiding this comment.
The arrow-function wrapper passes all arguments through to
sendEmailWithGmail unchanged, so it can be replaced with a direct assignment.
| app.locals.sendEmail = (recipientEmail, subject, content, user, options = {}) => { | |
| return sendEmailWithGmail(recipientEmail, subject, content, user, options); | |
| }; | |
| app.locals.sendEmail = sendEmailWithGmail; |
5e28db6 to
8fb8069
Compare
8fb8069 to
872c8a1
Compare
Summary
/api/auth/api/email/draftand/api/email/sendand derive the user from the verified JWTRelated to #2315
Tests
node --check plugins/apps-js/server.jsnode --check plugins/apps-js/email/src/routes/email.jsnode --check plugins/apps-js/email/src/routes/auth.jsgit diff --check