Skip to content

Commit ee31e9c

Browse files
CLDSRV-839: Limit warning to valid requests
S3 can receive many invalid requests, from internet scraper or other things. We don't want to warn for a request we can't process. Example warnings from lab / tests - apiMethod=undefined, method=OPTIONS, url=/bucketcorstester - apiMethod=undefined, method=POST, url=/ - apiMethod=undefined, method=DELETE, url=/bucketA - apiMethod=undefined, method=PUT, url=/as - apiMethod=undefined, method=PUT, url=/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - apiMethod=undefined, method=PUT, url=/192.168.5.4 - apiMethod=undefined, method=PUT, url=/.myawsbucket - apiMethod=undefined, method=PUT, url=/myawsbucket. - apiMethod=undefined, method=PUT, url=/my..examplebucket - apiMethod=undefined, method=PUT, url=/my.%23s3bucket
1 parent 42c9b34 commit ee31e9c

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

lib/utilities/serverAccessLogger.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,16 @@ function getOperation(req) {
297297
}
298298

299299
if (!resourceType) {
300-
process.emitWarning('Unknown apiMethod for server access log', {
301-
type: 'ServerAccessLogWarning',
302-
code: 'UNKNOWN_API_METHOD',
303-
detail: `apiMethod=${req.apiMethod}, method=${req.method}, url=${req.url}`
304-
});
300+
// Only emit a warning if apiMethod is not undefined, meaning request is valid.
301+
// Otherwise we could get spam by invalid or broken requests.
302+
// To help catch missing valid operation.
303+
if (req.apiMethod) {
304+
process.emitWarning('Unknown apiMethod for server access log', {
305+
type: 'ServerAccessLogWarning',
306+
code: 'UNKNOWN_API_METHOD',
307+
detail: `apiMethod=${req.apiMethod}, method=${req.method}, url=${req.url}`
308+
});
309+
}
305310
return `REST.${req.method}.UNKNOWN`;
306311
}
307312

0 commit comments

Comments
 (0)