Skip to content

BE-572: User email management improvements#8735

Merged
CiaranMn merged 8 commits into
mainfrom
cm/user-email-controls
May 20, 2026
Merged

BE-572: User email management improvements#8735
CiaranMn merged 8 commits into
mainfrom
cm/user-email-controls

Conversation

@CiaranMn
Copy link
Copy Markdown
Member

🌟 What is the purpose of this PR?

Security hardening:

  1. Disable Kratos self-service profile updates (stop users updating their own traits, which should be managed via our API)
  2. Check for email verification status when taking actions that should require it (e.g. to do with org invites)

Plus cleaning up some function arguments that weren't being used.

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

🛡 What tests cover this?

  • Existing tests to do with signing up / in.
  • Additional test added to check users cannot update traits via Kratos selfservice.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
hash Ignored Ignored Preview May 20, 2026 5:24pm
hashdotdesign-tokens Ignored Ignored Preview May 20, 2026 5:24pm
petrinaut Skipped Skipped May 20, 2026 5:24pm

@cursor
Copy link
Copy Markdown

cursor Bot commented May 20, 2026

PR Summary

Medium Risk
Tightens signup and org-invitation authorization around verified emails and changes userHasAccessToHash to return structured results; mistakes could block legitimate users from completing signup or accepting/declining invites.

Overview
Hardens identity/email security around Kratos and org invites. Kratos self-service profile settings are disabled so users can’t mutate identity traits (emails) outside HASH-controlled flows, and a new integration test asserts attempts to update profile traits are rejected.

Email verification is now treated as an explicit authorization signal: org invitation accept/decline checks match against getUserVerifiedEmails() (Kratos verifiable_addresses) rather than user.emails, and incomplete-user signup completion now enforces verification of the specific allow-listed email(s) when access is granted via USER_EMAIL_ALLOW_LIST.

Separately, userHasAccessToHash now returns { allowed, onlyForEmails } and getUser lookup is narrowed to stable identifiers (removing email-only lookup), with inviteUserToOrg using a new checkEmailVerificationAndUsageStatus() Kratos lookup + email normalization.

Reviewed by Cursor Bugbot for commit 03ad748. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added area/apps > hash* Affects HASH (a `hash-*` app) area/apps > hash-api Affects the HASH API (app) type/eng > backend Owned by the @backend team area/tests New or updated tests area/tests > integration New or updated integration tests area/apps labels May 20, 2026
@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented May 20, 2026

🤖 Augment PR Summary

Summary: This PR hardens user email management by tightening how email verification is used for authorization-sensitive flows and by preventing direct mutation of Kratos identity traits.

Changes:

  • Disabled Kratos self-service profile settings flow to stop users updating identity traits directly.
  • Added helpers to derive verified email addresses from Kratos identities and reused them across the API.
  • Updated org invitation accept/decline flows to require that invitations-by-email match a user’s verified email addresses.
  • Updated org invite creation to check whether a target email is in use and verified before resolving an existing user.
  • Refactored getUser to accept stable identifiers only (entityId/shortname/kratosIdentityId) and always source emails from Kratos.
  • Adjusted userHasAccessToHash to return structured results and to surface allow-list email matches for later verification checks.
  • Added an integration test ensuring Kratos profile trait updates via settings flows are rejected.

Technical Notes: Email verification is now treated as an authorization signal for certain actions (e.g., org invite flows), and email trait reads are centralized around Kratos verifiable addresses.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread apps/hash-api/src/auth/create-auth-handlers.ts Outdated
Comment thread apps/hash-api/src/graph/knowledge/system-types/user.ts
Comment thread apps/hash-api/src/graphql/resolvers/knowledge/org/invite-user-to-org.ts Outdated
@vercel vercel Bot temporarily deployed to Preview – petrinaut May 20, 2026 15:59 Inactive
@vercel vercel Bot temporarily deployed to Preview – petrinaut May 20, 2026 16:04 Inactive
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 0% with 49 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.71%. Comparing base (56860d0) to head (5f099ca).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
.../hash-api/src/graph/knowledge/system-types/user.ts 0.00% 13 Missing ⚠️
...y-hooks/user-before-update-entity-hook-callback.ts 0.00% 8 Missing ⚠️
...phql/resolvers/knowledge/org/invite-user-to-org.ts 0.00% 8 Missing ⚠️
...pps/hash-api/src/shared/user-has-access-to-hash.ts 0.00% 8 Missing ⚠️
apps/hash-api/src/auth/ory-kratos.ts 0.00% 6 Missing ⚠️
...l/resolvers/knowledge/org/accept-org-invitation.ts 0.00% 2 Missing ⚠️
.../resolvers/knowledge/org/decline-org-invitation.ts 0.00% 2 Missing ⚠️
...hql/resolvers/knowledge/user/has-access-to-hash.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8735      +/-   ##
==========================================
- Coverage   62.72%   62.71%   -0.02%     
==========================================
  Files        1363     1363              
  Lines      139062   139087      +25     
  Branches     5818     5825       +7     
==========================================
  Hits        87225    87225              
- Misses      50921    50946      +25     
  Partials      916      916              
Flag Coverage Δ
apps.hash-api 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

TimDiekmann
TimDiekmann previously approved these changes May 20, 2026
@vercel vercel Bot temporarily deployed to Preview – petrinaut May 20, 2026 16:18 Inactive
@github-actions github-actions Bot added the area/infra Relates to version control, CI, CD or IaC (area) label May 20, 2026
@CiaranMn CiaranMn force-pushed the cm/user-email-controls branch from 20550c5 to 8974830 Compare May 20, 2026 16:29
@vercel vercel Bot temporarily deployed to Preview – petrinaut May 20, 2026 16:29 Inactive
@github-actions github-actions Bot removed the area/infra Relates to version control, CI, CD or IaC (area) label May 20, 2026
@CiaranMn CiaranMn requested a review from TimDiekmann May 20, 2026 16:30
@CiaranMn CiaranMn enabled auto-merge May 20, 2026 16:30
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8974830. Configure here.

Comment thread apps/hash-api/src/graph/knowledge/system-types/user.ts
TimDiekmann
TimDiekmann previously approved these changes May 20, 2026
@vercel vercel Bot temporarily deployed to Preview – petrinaut May 20, 2026 16:37 Inactive
TimDiekmann
TimDiekmann previously approved these changes May 20, 2026
@github-actions github-actions Bot dismissed stale reviews from TimDiekmann and TimDiekmann May 20, 2026 16:42
@CiaranMn CiaranMn requested a review from vilkinsons May 20, 2026 16:57
@vercel vercel Bot temporarily deployed to Preview – petrinaut May 20, 2026 17:24 Inactive
@CiaranMn CiaranMn added this pull request to the merge queue May 20, 2026
Merged via the queue into main with commit 2777c6f May 20, 2026
47 checks passed
@CiaranMn CiaranMn deleted the cm/user-email-controls branch May 20, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/apps > hash* Affects HASH (a `hash-*` app) area/apps > hash-api Affects the HASH API (app) area/apps area/tests > integration New or updated integration tests area/tests New or updated tests type/eng > backend Owned by the @backend team

Development

Successfully merging this pull request may close these issues.

2 participants