-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rate limits to email routes (#2129)
* add rate limits to email routes * did based only * tweak
- Loading branch information
Showing
4 changed files
with
66 additions
and
12 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
packages/pds/src/api/com/atproto/server/requestAccountDelete.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/pds/src/api/com/atproto/server/requestEmailConfirmation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/pds/src/api/com/atproto/server/requestEmailUpdate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 27 additions & 12 deletions
39
packages/pds/src/api/com/atproto/server/requestPasswordReset.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
) | ||
} | ||
}, | ||
}) | ||
} |