Lock In Lab Intern, rank 1 of 9

PR-2 Review: The agent's sign-in PR

You asked for email magic-link sign-in protecting POST /messages and a /mine page. The agent says it's done and all tests pass.

Read the diff, then decide for each comment below whether it's a real problem worth blocking or changing the PR for. You pass when every call is right. Take as many tries as you like.

server/routes.jsdiff from the agent
+app.post('/auth/callback', async (req, res) => {
+  const { token } = req.query;
+  const user = await auth.verifyMagicLink(token);
+  console.log('login ok', user.email, token);
+  res.cookie('session', await auth.createSession(user), {
+    httpOnly: true, secure: true, sameSite: 'lax', maxAge: 30 * 24 * 3600 * 1000,
+  });
+  res.redirect('/mine');
+});
+
+app.get('/mine', async (req, res) => {
+  res.sendFile('mine.html');   // mine.html redirects to /login if no user in localStorage
+});
+
+app.get('/api/mine', requireSession, async (req, res) => {
+  res.json(await db.messages.where({ userId: req.query.userId }));
+});
+
+app.post('/messages', requireSession, async (req, res) => {
+  await db.messages.insert({ userId: req.user.id, body: req.body.body.slice(0, 280) });
+  res.status(201).end();
+});

Review comments

  1. The magic-link token is written to the logs.

  2. /api/mine returns messages for whatever userId is in the query string.

  3. /mine is only protected by a redirect in the browser.

  4. The session cookie needs httpOnly and secure before this can merge.

  5. POST /messages should take the author's id from the request body.

  6. Thirty-day sessions must be cut to one hour before merging.

The checklist for next time

  1. Every route that returns private data checks the session on the server.
  2. Ids come from the session, never from the query or body.
  3. Tokens, cookies and keys never reach logs.
  4. Cookies: httpOnly, secure, SameSite.