@vizamodo/aws-sts-core 0.3.10 → 0.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sigv4/request.js +14 -2
- package/dist/sts/issue.js +15 -0
- package/package.json +1 -1
package/dist/sigv4/request.js
CHANGED
|
@@ -53,21 +53,33 @@ export async function buildSignedAwsRequest(input) {
|
|
|
53
53
|
iso.slice(17, 19) +
|
|
54
54
|
"Z";
|
|
55
55
|
const dateStamp = amzDate.slice(0, 8);
|
|
56
|
+
// SigV4: canonical headers must be sorted alphabetically by header name.
|
|
57
|
+
// x-amz-security-token sorts before x-amz-target → must appear first.
|
|
56
58
|
const canonicalHeaders = `content-type:${contentType}\n` +
|
|
57
59
|
`host:${host}\n` +
|
|
58
60
|
`x-amz-date:${amzDate}\n` +
|
|
59
|
-
`x-amz-target:${target}\n` +
|
|
60
61
|
(credentials.sessionToken
|
|
61
62
|
? `x-amz-security-token:${credentials.sessionToken}\n`
|
|
62
|
-
: "")
|
|
63
|
+
: "") +
|
|
64
|
+
`x-amz-target:${target}\n`;
|
|
65
|
+
// signedHeaders must list header names in the same alphabetical order.
|
|
63
66
|
const signedHeaders = credentials.sessionToken
|
|
64
67
|
? "content-type;host;x-amz-date;x-amz-security-token;x-amz-target"
|
|
65
68
|
: "content-type;host;x-amz-date;x-amz-target";
|
|
66
69
|
const payloadHash = await sha256Hex(body);
|
|
70
|
+
// SigV4 canonical request format:
|
|
71
|
+
// METHOD\n
|
|
72
|
+
// URI\n
|
|
73
|
+
// QueryString\n
|
|
74
|
+
// CanonicalHeaders\n ← each header ends with \n, so last header already adds one
|
|
75
|
+
// \n ← required blank line separating headers from signedHeaders
|
|
76
|
+
// SignedHeaders\n
|
|
77
|
+
// PayloadHash
|
|
67
78
|
const canonicalRequest = "POST\n" +
|
|
68
79
|
"/\n" +
|
|
69
80
|
"\n" +
|
|
70
81
|
canonicalHeaders +
|
|
82
|
+
"\n" + // ← blank line between canonical headers and signed headers
|
|
71
83
|
signedHeaders +
|
|
72
84
|
"\n" +
|
|
73
85
|
payloadHash;
|
package/dist/sts/issue.js
CHANGED
|
@@ -136,15 +136,30 @@ export async function issueAwsCredentials(input) {
|
|
|
136
136
|
// ---- STS credential cache lookup (using certificate serial) ----
|
|
137
137
|
cacheKey = `${region}|${roleArn}|${profileArn}|${trustAnchorArn}|${certSerialDec}`;
|
|
138
138
|
const cachedEntry = stsCredentialCache.get(cacheKey);
|
|
139
|
+
if (cachedEntry) {
|
|
140
|
+
console.log("[sts-cache] hit", {
|
|
141
|
+
cacheKey,
|
|
142
|
+
expiresAt: cachedEntry.expiresAt,
|
|
143
|
+
now: Date.now(),
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
console.log("[sts-cache] miss", { cacheKey });
|
|
148
|
+
}
|
|
139
149
|
// Only reuse cached credentials if they still have >10p remaining
|
|
140
150
|
const MIN_REMAINING_MS = 5 * 60 * 1000;
|
|
141
151
|
if (cachedEntry) {
|
|
142
152
|
// If refresh already in-flight → await the same promise
|
|
143
153
|
if (cachedEntry.expiresAt === 0) {
|
|
154
|
+
console.log("[sts-cache] reuse-inflight-refresh", { cacheKey });
|
|
144
155
|
return cachedEntry.promise;
|
|
145
156
|
}
|
|
146
157
|
// If credentials still valid with safe remaining window → reuse
|
|
147
158
|
if (cachedEntry.expiresAt > Date.now() + MIN_REMAINING_MS) {
|
|
159
|
+
console.log("[sts-cache] reuse-valid-credentials", {
|
|
160
|
+
cacheKey,
|
|
161
|
+
expiresAt: cachedEntry.expiresAt,
|
|
162
|
+
});
|
|
148
163
|
return cachedEntry.promise;
|
|
149
164
|
}
|
|
150
165
|
}
|