Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rate limits to email routes #2129

Merged
merged 3 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/pds/src/api/com/atproto/server/requestAccountDelete.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { InvalidRequestError } from '@atproto/xrpc-server'
import { DAY, HOUR } from '@atproto/common'
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'

export default function (server: Server, ctx: AppContext) {
server.com.atproto.server.requestAccountDelete({
rateLimit: [
{
durationMs: DAY,
points: 15,
calcKey: ({ auth }) => auth.credentials.did,
},
{
durationMs: HOUR,
points: 5,
calcKey: ({ auth }) => auth.credentials.did,
},
],
auth: ctx.authVerifier.accessCheckTakedown,
handler: async ({ auth }) => {
const did = auth.credentials.did
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { InvalidRequestError } from '@atproto/xrpc-server'
import { DAY, HOUR } from '@atproto/common'
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'

export default function (server: Server, ctx: AppContext) {
server.com.atproto.server.requestEmailConfirmation({
rateLimit: [
{
durationMs: DAY,
points: 15,
calcKey: ({ auth }) => auth.credentials.did,
},
{
durationMs: HOUR,
points: 5,
calcKey: ({ auth }) => auth.credentials.did,
},
],
auth: ctx.authVerifier.accessCheckTakedown,
handler: async ({ auth }) => {
const did = auth.credentials.did
Expand Down
13 changes: 13 additions & 0 deletions packages/pds/src/api/com/atproto/server/requestEmailUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { InvalidRequestError } from '@atproto/xrpc-server'
import { DAY, HOUR } from '@atproto/common'
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'

export default function (server: Server, ctx: AppContext) {
server.com.atproto.server.requestEmailUpdate({
rateLimit: [
{
durationMs: DAY,
points: 15,
calcKey: ({ auth }) => auth.credentials.did,
},
{
durationMs: HOUR,
points: 5,
calcKey: ({ auth }) => auth.credentials.did,
},
],
auth: ctx.authVerifier.accessCheckTakedown,
handler: async ({ auth }) => {
const did = auth.credentials.did
Expand Down
39 changes: 27 additions & 12 deletions packages/pds/src/api/com/atproto/server/requestPasswordReset.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
import { DAY, HOUR } from '@atproto/common'
import AppContext from '../../../../context'
import { Server } from '../../../../lexicon'

export default function (server: Server, ctx: AppContext) {
server.com.atproto.server.requestPasswordReset(async ({ input }) => {
const email = input.body.email.toLowerCase()
server.com.atproto.server.requestPasswordReset({
rateLimit: [
{
durationMs: DAY,
points: 15,
calcKey: ({ input }) => input.body.email.toLowerCase(),
},
{
durationMs: HOUR,
points: 5,
calcKey: ({ input }) => input.body.email.toLowerCase(),
},
],
handler: async ({ input }) => {
const email = input.body.email.toLowerCase()

const user = await ctx.services.account(ctx.db).getAccountByEmail(email)
const user = await ctx.services.account(ctx.db).getAccountByEmail(email)

if (user) {
const token = await ctx.services
.account(ctx.db)
.createEmailToken(user.did, 'reset_password')
await ctx.mailer.sendResetPassword(
{ handle: user.handle, token },
{ to: user.email },
)
}
if (user) {
const token = await ctx.services
.account(ctx.db)
.createEmailToken(user.did, 'reset_password')
await ctx.mailer.sendResetPassword(
{ handle: user.handle, token },
{ to: user.email },
)
}
},
})
}
Loading