fix: strip trailing slash in SigV4 canonical URI
Deploy FileDrop / deploy (push) Successful in 36s
Deploy FileDrop / deploy (push) Successful in 36s
AWS SigV4 canonical URI must not have trailing slash (except root '/'). Bun can receive paths with trailing slash from SDK, causing signature mismatch for all bucket operations (CreateBucket, HeadBucket, etc.) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+2
-12
@@ -1,5 +1,4 @@
|
|||||||
import { timingSafeEqual } from 'node:crypto';
|
import { timingSafeEqual } from 'node:crypto';
|
||||||
import logger from '../../shared/logger/index';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timing-safe string comparison that prevents timing attacks.
|
* Timing-safe string comparison that prevents timing attacks.
|
||||||
@@ -167,9 +166,9 @@ const normalizeUri = (uri: string): string => {
|
|||||||
result.push(segment);
|
result.push(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reconstruct path
|
// Reconstruct path (no trailing slash except root)
|
||||||
const normalized = result.length > 0 ? `/${result.join('/')}` : '/';
|
const normalized = result.length > 0 ? `/${result.join('/')}` : '/';
|
||||||
return normalized;
|
return normalized === '/' ? '/' : normalized.replace(/\/+$/, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
const awsEncode = (value: string): string =>
|
const awsEncode = (value: string): string =>
|
||||||
@@ -300,15 +299,6 @@ export const verifySignature = async (
|
|||||||
|
|
||||||
const hashedCanonicalRequest = await sha256Hex(canonicalRequest);
|
const hashedCanonicalRequest = await sha256Hex(canonicalRequest);
|
||||||
|
|
||||||
// Debug canonical request for non-root GETs (bucket operations)
|
|
||||||
logger.info('SigV4 canonical request', {
|
|
||||||
method,
|
|
||||||
path: parsedUrl.pathname,
|
|
||||||
signedHeaders: parsed.signedHeaders,
|
|
||||||
hashedPayload: hashedPayload.slice(0, 20) + '...',
|
|
||||||
canReq: canonicalRequest.slice(0, 500),
|
|
||||||
});
|
|
||||||
|
|
||||||
// M1: Fall back to Date header if x-amz-date is missing
|
// M1: Fall back to Date header if x-amz-date is missing
|
||||||
const amzDate = headers['x-amz-date'] || headers['date'] || '';
|
const amzDate = headers['x-amz-date'] || headers['date'] || '';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user