Skip to content

Commit

Permalink
Validate OAuth sign-up handle using @atproto/syntax
Browse files Browse the repository at this point in the history
Fixes #3619
  • Loading branch information
matthieusieben committed Mar 10, 2025
1 parent 7a7f2c4 commit de3270b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-cheetahs-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/oauth-provider": patch
---

Properly validate handle syntax during sign-up
1 change: 1 addition & 0 deletions packages/oauth/oauth-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@atproto/jwk": "workspace:*",
"@atproto/jwk-jose": "workspace:*",
"@atproto/oauth-types": "workspace:*",
"@atproto/syntax": "workspace:*",
"@hapi/accept": "^6.0.3",
"@hapi/address": "^5.1.1",
"@hapi/bourne": "^3.0.0",
Expand Down
16 changes: 13 additions & 3 deletions packages/oauth/oauth-provider/src/account/account-store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isEmailValid } from '@hapi/address'
import { isDisposableEmail } from 'disposable-email-domains-js'
import { z } from 'zod'
import { ensureValidHandle } from '@atproto/syntax'
import { ClientId } from '../client/client-id.js'
import { DeviceId } from '../device/device-id.js'
import { localeSchema } from '../lib/locale.js'
Expand All @@ -19,9 +20,18 @@ export const newPasswordSchema = z.string().min(8)
export const tokenSchema = z.string().regex(/^[A-Z2-7]{5}-[A-Z2-7]{5}$/)
export const handleSchema = z
.string()
.min(3)
.max(30)
.regex(/^[a-z0-9][a-z0-9-]+[a-z0-9](?:\.[a-z0-9][a-z0-9-]+[a-z0-9])+$/)
// @NOTE: We only check against validity towards ATProto's syntax. Additional
// rules may be imposed by the store implementation.
.superRefine((value, ctx) => {
try {
ensureValidHandle(value)
} catch (err) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: err instanceof Error ? err.message : 'Invalid handle',
})
}
})
export const emailSchema = z
.string()
.email()
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit de3270b

Please sign in to comment.