@@ -96,12 +96,14 @@ export function createIpAllowlist(config: IpAllowlistConfig) {
9696 }
9797
9898 // Log configuration for security audit
99- logger . info ( 'IP allowlist middleware configured' , {
100- allowedRangesCount : allowedRanges . length ,
101- trustProxy,
102- proxyHeaders,
103- enabled,
104- } ) ;
99+ logger . info (
100+ `IP allowlist middleware configured ${ JSON . stringify ( {
101+ allowedRangesCount : allowedRanges . length ,
102+ trustProxy,
103+ proxyHeaders,
104+ enabled,
105+ } ) } `
106+ ) ;
105107
106108 return ( req : Request , res : Response , next : NextFunction ) : void => {
107109 // Skip IP checking if allowlist is disabled
@@ -114,11 +116,13 @@ export function createIpAllowlist(config: IpAllowlistConfig) {
114116
115117 // Validate extracted IP format
116118 if ( ! isValidIp ( clientIp ) ) {
117- logger . warn ( 'Invalid IP format detected' , {
118- ip : clientIp ,
119- userAgent : req . get ( 'User-Agent' ) ,
120- path : req . path ,
121- } ) ;
119+ logger . warn (
120+ `Invalid IP format detected ${ JSON . stringify ( {
121+ ip : clientIp ,
122+ userAgent : req . get ( 'User-Agent' ) ,
123+ path : req . path ,
124+ } ) } `
125+ ) ;
122126
123127 res . status ( 400 ) . json ( {
124128 error : 'Bad Request: invalid client IP format' ,
@@ -132,13 +136,15 @@ export function createIpAllowlist(config: IpAllowlistConfig) {
132136
133137 if ( ! isAllowed ) {
134138 // Log blocked attempt for security monitoring
135- logger . warn ( 'IP allowlist blocked request' , {
136- clientIp,
137- path : req . path ,
138- method : req . method ,
139- userAgent : req . get ( 'User-Agent' ) ,
140- timestamp : new Date ( ) . toISOString ( ) ,
141- } ) ;
139+ logger . warn (
140+ `IP allowlist blocked request ${ JSON . stringify ( {
141+ clientIp,
142+ path : req . path ,
143+ method : req . method ,
144+ userAgent : req . get ( 'User-Agent' ) ,
145+ timestamp : new Date ( ) . toISOString ( ) ,
146+ } ) } `
147+ ) ;
142148
143149 res . status ( 403 ) . json ( {
144150 error : 'Forbidden: IP address not allowed' ,
@@ -148,11 +154,13 @@ export function createIpAllowlist(config: IpAllowlistConfig) {
148154 }
149155
150156 // Log successful allowlist check for audit trail
151- logger . debug ( 'IP allowlist check passed' , {
152- clientIp,
153- path : req . path ,
154- method : req . method ,
155- } ) ;
157+ logger . info (
158+ `IP allowlist check passed ${ JSON . stringify ( {
159+ clientIp,
160+ path : req . path ,
161+ method : req . method ,
162+ } ) } `
163+ ) ;
156164
157165 next ( ) ;
158166 } ;
0 commit comments