Skip to content

Fix: JWT callback allows client-controlled email spoofing via session.update() - #80

Merged
shammy911 merged 2 commits into
KavinduSDfrom
copilot/sub-pr-79
Mar 20, 2026
Merged

shammy911 merged 2 commits into
KavinduSDfrom
copilot/sub-pr-79

Conversation

Copilot AI commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor

The jwt callback was applying session.update() payloads directly to token.email, letting any authenticated client overwrite their JWT email — bypassing any downstream authorization or DB lookups that trust session.user.email.

Changes

  • Drop client-provided email from session.update() handler — only name updates are accepted; email is never taken from client-supplied session payloads.
  • Re-hydrate token.email from DB for regular users — on every JWT refresh, email is sourced from the DB via the trusted token.id, matching the existing pattern for admin/advisor accounts.
// Before — client controls token.email
if (trigger === "update" && session) {
  if (typeof session.name === "string") token.name = session.name;
  if (typeof session.email === "string") token.email = session.email; // ❌
}

// After — email always sourced from DB
if (trigger === "update" && session) {
  if (typeof session.name === "string") token.name = session.name;
  // email intentionally omitted
}
// ...
} else if (token.userType === "user" && token.id) {
  const user = await prisma.user.findUnique({ where: { id: token.id }, select: { email: true } });
  if (user) token.email = user.email; // ✅ authoritative source
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Remove token.email = session.email from session.update() handler;
  client-controlled email was being written directly to the JWT token,
  enabling session.user.email spoofing.
- Add DB re-hydration of token.email for regular users (userType=user)
  using token.id, consistent with the existing pattern for admin/advisor.
- Add a warning log when the user record is not found during re-hydration.

Co-authored-by: shammy911 <180457932+shammy911@users.noreply.github.com>

Copilot AI commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkpoint.prisma.io
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node /home/REDACTED/work/Smart-Auto-Hub/Smart-Auto-Hub/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.19.2&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-03-20T06:12:36Z&#34;,&#34;project_hash&#34;:&#34;56f9ffc6&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/Smart-Auto-Hub/Smart-Auto-Hub/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;8c (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] [WIP] Address feedback from PR #79 for improvements Fix: JWT callback allows client-controlled email spoofing via session.update() Mar 20, 2026
Copilot AI requested a review from shammy911 March 20, 2026 06:15
@shammy911
shammy911 marked this pull request as ready for review March 20, 2026 06:17
@shammy911
shammy911 merged commit b03410c into KavinduSD Mar 20, 2026
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.

2 participants