File tree Expand file tree Collapse file tree 2 files changed +17
-14
lines changed Expand file tree Collapse file tree 2 files changed +17
-14
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,14 @@ import { logger } from './logger.js'
5
5
const JWT_SECRET = process . env . JWT_SECRET
6
6
7
7
export function logIncomingAuth ( req : Request , res : Response , next : NextFunction ) {
8
- logger . debug ( 'Incoming headers:' , req . headers )
8
+ logger . info (
9
+ `[AUTH] ${ req . headers [ 'cf-connecting-ip' ] ?? req . ip } - ${ req . headers [ 'cf-ipcountry' ] ?? 'unknown country' } `
10
+ )
9
11
10
12
const authHeader = req . headers . authorization
11
13
if ( ! authHeader ?. startsWith ( 'Bearer ' ) ) {
12
14
logger . warn ( 'No auth header or bad format' )
15
+ logger . debug ( 'Incoming headers:' , req . headers )
13
16
} else {
14
17
const token = authHeader . split ( ' ' ) [ 1 ]
15
18
logger . debug ( 'Inspecting token:' , token )
Original file line number Diff line number Diff line change @@ -4,16 +4,16 @@ import { logger } from './logger.js'
4
4
import { Response } from 'express'
5
5
6
6
export const rateLimiter : RateLimitRequestHandler = rateLimit ( {
7
- windowMs : 60 * 1000 ,
8
- limit : ( req : Request ) : number => {
9
- logger . debug ( `Rate limit check ${ req . auth ? 'authenticated' : 'anon' } - ${ req . headers [ 'cf-connecting-ip' ] ?? req . ip } ` )
10
- return req . auth ? 60 : 5 // 60 req/min for auth, 5 for anon
11
- } ,
12
- keyGenerator : ( req : Request ) : string => {
13
- return req . auth ?. sub ? `session-${ req . auth . sub } ` : req . ip !
14
- } ,
15
- handler : ( req : Request , res : Response ) => {
16
- logger . warn ( 'Rate limiting IP address:' , req . ip )
17
- res . status ( 429 ) . send ( { message : 'Rate limited' } )
18
- }
19
- } )
7
+ windowMs : 60 * 1000 ,
8
+ limit : ( req : Request ) : number => {
9
+ logger . info ( `Rate limit check ${ req . auth ? 'authenticated' : 'anon' } - ${ req . headers [ 'cf-connecting-ip' ] ?? req . ip } ` )
10
+ return req . auth ? 60 : 5 // 60 req/min for auth, 5 for anon
11
+ } ,
12
+ keyGenerator : ( req : Request ) : string => {
13
+ return req . auth ?. sub ? `session-${ req . auth . sub } ` : req . ip !
14
+ } ,
15
+ handler : ( req : Request , res : Response ) => {
16
+ logger . warn ( 'Rate limiting IP address:' , req . ip )
17
+ res . status ( 429 ) . send ( { message : 'Rate limited' } )
18
+ } ,
19
+ } )
You can’t perform that action at this time.
0 commit comments