@@ -15,14 +15,14 @@ import { nowIso, randomId, safeReturnTo, setFlash } from "../utils.js";
1515export function authRoutes ( { store, config } ) {
1616 const router = Router ( ) ;
1717 const attempts = new Map ( ) ;
18- const limit = ( req , res , next ) => {
18+ const rateLimit = ( req , res , next ) => {
1919 const key = `${ req . ip } :${ req . path } ` ; const now = Date . now ( ) ;
2020 const recent = ( attempts . get ( key ) || [ ] ) . filter ( ( time ) => now - time < 60_000 ) ;
2121 if ( recent . length >= 30 ) return res . status ( 429 ) . send ( "Too many authentication attempts. Try again shortly." ) ;
2222 recent . push ( now ) ; attempts . set ( key , recent ) ; return next ( ) ;
2323 } ;
2424
25- router . get ( "/login" , limit , async ( req , res ) => {
25+ router . get ( "/login" , rateLimit , async ( req , res ) => {
2626 const returnTo = safeReturnTo ( req . query . return_to , "/app/profile" ) ;
2727 const forceReauth = req . forceReauth || req . query . reauth === "1" ;
2828 if ( req . user && ! forceReauth ) return res . redirect ( returnTo ) ;
@@ -34,7 +34,7 @@ export function authRoutes({ store, config }) {
3434 } ) ;
3535 } ) ;
3636
37- router . get ( "/callback" , limit , async ( req , res ) => {
37+ router . get ( "/callback" , rateLimit , async ( req , res ) => {
3838 if ( req . query . error ) {
3939 return res . status ( 400 ) . render ( "error" , {
4040 title : "Sign in cancelled" ,
@@ -68,7 +68,7 @@ export function authRoutes({ store, config }) {
6868 res . redirect ( "/" ) ;
6969 } ) ;
7070
71- router . post ( "/dev-login" , limit , async ( req , res ) => {
71+ router . post ( "/dev-login" , rateLimit , async ( req , res ) => {
7272 if ( ! config . devAuthBypass ) return res . sendStatus ( 404 ) ;
7373 const timestamp = nowIso ( ) ;
7474 const email = String ( req . body . email || "radio-maker@example.com" ) . trim ( ) . toLowerCase ( ) ;
0 commit comments