Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(storage): trim S3 credentials so a padded key stops reading as a wrong key

nirholas36b67b8a8d57
diff --git a/api/_lib/env.js b/api/_lib/env.js
index 8ec199036..13f098dd0 100644
--- a/api/_lib/env.js
+++ b/api/_lib/env.js
@@ -23,6 +23,19 @@ function trimSlash(s) {
// checksum. Trim address-like env values at the source so no consumer ever
// emits whitespace into a 402 challenge. Returns undefined when blank so the
// `if (env.X402_PAY_TO_SOLANA)` guards downstream still skip cleanly.
+// A credential pasted into a dashboard, echoed into a Secret Manager payload, or
+// copied out of a provider console frequently carries a trailing newline or a
+// stray space. For an S3-compatible key that whitespace is invisible and fatal:
+// the SDK signs the request with the padded secret and the store answers
+// `SignatureDoesNotMatch`, which reads as "wrong key" rather than "wrong
+// bytes". Trim credential-class values at the source, the same way addr() does
+// for addresses, so no signer ever sees the padding.
+function secret(name) {
+ const v = req(name).trim();
+ if (!v) throw new Error(`Missing required env var: ${name}`);
+ return v;
+}
+
function addr(value) {
if (value == null) return value;
const v = String(value).trim();
@@ -283,10 +296,10 @@ export const env = {
return trimSlash(req('S3_ENDPOINT'));
},
get S3_ACCESS_KEY_ID() {
- return req('S3_ACCESS_KEY_ID');
+ return secret('S3_ACCESS_KEY_ID');
},
get S3_SECRET_ACCESS_KEY() {
- return req('S3_SECRET_ACCESS_KEY');
+ return secret('S3_SECRET_ACCESS_KEY');
},
get S3_BUCKET() {
return req('S3_BUCKET');
diff --git a/api/_lib/r2.js b/api/_lib/r2.js
index ad76e08dc..24d6343ab 100644
--- a/api/_lib/r2.js
+++ b/api/_lib/r2.js
@@ -47,12 +47,16 @@ export const r2 = new Proxy(
// claim a batch of work and fail every item on `Missing required env var: S3_…`
// gate on this and skip the tick instead (api/cron/avatar-thumbnail-*.js).
export function objectStorageConfigured() {
- return Boolean(
- process.env.S3_ENDPOINT &&
- process.env.S3_BUCKET &&
- process.env.S3_PUBLIC_DOMAIN &&
- process.env.S3_ACCESS_KEY_ID &&
- process.env.S3_SECRET_ACCESS_KEY,
+ // Trimmed, because a credential that is nothing but a newline is not
+ // configured storage: it signs every request into a `SignatureDoesNotMatch`
+ // while every truthiness check above it reads healthy (see env.js secret()).
+ const set = (name) => Boolean(String(process.env[name] ?? '').trim());
+ return (
+ set('S3_ENDPOINT') &&
+ set('S3_BUCKET') &&
+ set('S3_PUBLIC_DOMAIN') &&
+ set('S3_ACCESS_KEY_ID') &&
+ set('S3_SECRET_ACCESS_KEY')
);
}