Skip to content

Validate fallback email field as valid address before passing to EmailStr#91

Merged
AlexAxthelm merged 2 commits into
mainfrom
fix/validate-fallback-email
May 13, 2026
Merged

Validate fallback email field as valid address before passing to EmailStr#91
AlexAxthelm merged 2 commits into
mainfrom
fix/validate-fallback-email

Conversation

@AlexAxthelm
Copy link
Copy Markdown
Collaborator

@AlexAxthelm AlexAxthelm commented May 12, 2026

implemented by codex

Followup to #85, validates the fallback preferred_username as an email before writing it to the email user field.

Note to reviewers: Opening this as one possible way to preserve the meaning of email field. Alternately, we could not use EmailStr validation, and just store a str, but in that case, I would suggest we call it something other than email in our data model

@AlexAxthelm AlexAxthelm marked this pull request as draft May 12, 2026 09:27
@github-actions
Copy link
Copy Markdown

CD summary f0072d9

Frontend: https://witty-mushroom-017a3dc1e-91.westus2.1.azurestaticapps.net

Deployments (4)
service url fqdn
api open pr91-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io
entity-linkage open pr91-entity-linkage.purplegrass-c07d0a94.westus2.azurecontainerapps.io
frontend https://witty-mushroom-017a3dc1e-91.westus2.1.azurestaticapps.net
stitch-llm open pr91-stitch-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io
Database (1)
db_name postgres_host postgres_port postgres_db
pr_91 stitch-dev.postgres.database.azure.com 5432 pr_91
Jobs (2)
job image postgres_db api_url auth_mode
db-init ghcr.io/rmi/stitch-api:pr91@sha256:23829d38a903e3d2255e1afb1444a024273da3c0f1476b88a1e9767dfe633930 pr_91
seed ghcr.io/rmi/stitch-seed:pr91@sha256:817be71a839edbee4cbe62b9e092d6975b3a9ea928e1a6d1e1cc7ce1cec8ccdf https://pr91-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io/api/v1 dev placeholder bearer token
Images (4)
build_time commit_time git_sha image image_digest
2026-05-12T09:22:23Z 2026-05-12T09:22:11Z 265a000 ghcr.io/rmi/stitch-api:pr91 ghcr.io/rmi/stitch-api:pr91@sha256:23829d38a903e3d2255e1afb1444a024273da3c0f1476b88a1e9767dfe633930
2026-05-12T09:22:25Z 2026-05-12T09:22:11Z 265a000 ghcr.io/rmi/stitch-entity-linkage:pr91 ghcr.io/rmi/stitch-entity-linkage:pr91@sha256:321cc5e045b296b37822e3625e930f3bcce78b0c720ad442701f5656c6d5af7a
2026-05-12T09:22:33Z 2026-05-12T09:22:11Z 265a000 ghcr.io/rmi/stitch-seed:pr91 ghcr.io/rmi/stitch-seed:pr91@sha256:817be71a839edbee4cbe62b9e092d6975b3a9ea928e1a6d1e1cc7ce1cec8ccdf
2026-05-12T09:22:29Z 2026-05-12T09:22:11Z 265a000 ghcr.io/rmi/stitch-stitch-llm:pr91 ghcr.io/rmi/stitch-stitch-llm:pr91@sha256:c60904ff51ea21d9f4272b358c84dbb6a7625a4dc48cc729e1cf1037431e4159

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens how stitch-auth derives TokenClaims.email from OIDC payloads by only accepting email-like values (including when falling back to preferred_username), preventing non-email usernames from being written into the email field downstream.

Changes:

  • Added _validated_email() to filter/validate email and preferred_username payload values before setting TokenClaims.email.
  • Updated JWTValidator.validate() to prefer a validated email claim and otherwise fall back to a validated preferred_username.
  • Added unit tests covering invalid preferred_username fallback and malformed email claim behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/stitch-auth/src/stitch/auth/validator.py Adds email validation helper and applies it to email / preferred_username claim extraction.
packages/stitch-auth/tests/test_validator_unit.py Adds unit tests for ignoring non-email preferred_username and falling back when email is malformed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/stitch-auth/src/stitch/auth/validator.py
@AlexAxthelm AlexAxthelm changed the title Validate fallback email field as EmailStr Validate fallback email field as valid address before passing to EmailStr May 12, 2026
@AlexAxthelm AlexAxthelm marked this pull request as ready for review May 12, 2026 09:35
@AlexAxthelm AlexAxthelm requested a review from mbarlow12 May 12, 2026 09:35
@github-actions
Copy link
Copy Markdown

CD summary 83dde24

Frontend: https://witty-mushroom-017a3dc1e-91.westus2.1.azurestaticapps.net

Deployments (4)
service url fqdn
api open pr91-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io
entity-linkage open pr91-entity-linkage.purplegrass-c07d0a94.westus2.azurecontainerapps.io
frontend https://witty-mushroom-017a3dc1e-91.westus2.1.azurestaticapps.net
stitch-llm open pr91-stitch-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io
Database (1)
db_name postgres_host postgres_port postgres_db
pr_91 stitch-dev.postgres.database.azure.com 5432 pr_91
Jobs (1)
job image postgres_db
db-init ghcr.io/rmi/stitch-api:pr91@sha256:b9a58c0136851d6fd36bea5d3ff5cae9e127315ad82fb50366880b4c77f5b174 pr_91
Images (4)
build_time commit_time git_sha image image_digest
2026-05-12T09:29:17Z 2026-05-12T09:29:05Z 12e1ef0 ghcr.io/rmi/stitch-api:pr91 ghcr.io/rmi/stitch-api:pr91@sha256:b9a58c0136851d6fd36bea5d3ff5cae9e127315ad82fb50366880b4c77f5b174
2026-05-12T09:29:22Z 2026-05-12T09:29:05Z 12e1ef0 ghcr.io/rmi/stitch-entity-linkage:pr91 ghcr.io/rmi/stitch-entity-linkage:pr91@sha256:7947b8e8bf457df63942fb9359b0c240a7396ac5d66748d8d3349c8114dc1756
2026-05-12T09:29:15Z 2026-05-12T09:29:05Z 12e1ef0 ghcr.io/rmi/stitch-seed:pr91 ghcr.io/rmi/stitch-seed:pr91@sha256:fd9c03f6f4731490b953652500c4b1040b20cde4a7753d9c46f23f2208131619
2026-05-12T09:29:19Z 2026-05-12T09:29:05Z 12e1ef0 ghcr.io/rmi/stitch-stitch-llm:pr91 ghcr.io/rmi/stitch-stitch-llm:pr91@sha256:92dfd0e814529502e6e6aff15556a4e5dc45a064dd14905e7795c4a17258c084

@AlexAxthelm AlexAxthelm merged commit 016eb8a into main May 13, 2026
30 checks passed
@AlexAxthelm AlexAxthelm deleted the fix/validate-fallback-email branch May 13, 2026 19:16
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.

3 participants