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(secrets): decide a URL var by its value, and take the first version of an empty secret

nirholasfa9700d86158
diff --git a/scripts/migrate-plaintext-secrets.mjs b/scripts/migrate-plaintext-secrets.mjs
index 3925b1ca3..355c906cd 100755
--- a/scripts/migrate-plaintext-secrets.mjs
+++ b/scripts/migrate-plaintext-secrets.mjs
@@ -121,8 +121,8 @@ const SECRET_SEGMENTS = new Set([
]);
// A name segment from this set means the value is a public identifier, even when
-// another segment matched above. In a crypto codebase TOKEN and KEY are heavily
-// overloaded: THREE_TOKEN_MINT is an address, not a credential.
+// another segment matched above. TOKEN and KEY are heavily overloaded here:
+// THREE_TOKEN_MINT is an address, not a credential.
const PUBLIC_SEGMENTS = new Set(['PUBLIC', 'PUBKEY', 'ADDRESS', 'MINT', 'ISSUER', 'AUDIENCE']);
// Suffixes that name a credential's handle rather than the credential itself.
@@ -171,7 +171,18 @@ function fail(msg) {
process.exit(1);
}
-export function classify(name) {
+// A provider URL routinely carries its key in the query string, and a database
+// URL carries its password as userinfo before the host. The NAME cannot say
+// whether a given one does, so the value is what decides: this returns true only
+// for a URL that actually carries a credential.
+export function urlCarriesCredential(value) {
+ if (!value) return false;
+ if (/[?&](api[-_]?key|apikey|key|token|secret|password|passwd|access[-_]?key|auth)=[^&\s]+/i.test(value)) return true;
+ const authority = String(value).split('//')[1]?.split(/[/?#]/)[0] || '';
+ return authority.includes('@');
+}
+
+export function classify(name, value) {
if (EXCLUDE.includes(name)) return { secret: false, reason: 'excluded by --exclude' };
if (INCLUDE.includes(name)) return { secret: true, reason: 'forced by --include' };
if (EXTRA_SECRETS.has(name)) return { secret: true, reason: 'known credential' };
@@ -186,7 +197,9 @@ export function classify(name) {
// QuickNode all do). The name cannot say whether this one does, so it is
// surfaced for a human call instead of being silently filed as public config.
if (/_(URL|URI|ENDPOINT)$/.test(name)) {
- return { secret: false, review: true, reason: 'URL: may embed a key in its query string' };
+ return urlCarriesCredential(value)
+ ? { secret: true, reason: 'URL carrying a credential in its query string or userinfo' }
+ : { secret: false, reason: 'URL with no credential in it' };
}
// A JWK is a public key half the time and a signing key the other half. The
// name cannot tell them apart, so an operator decides.
@@ -264,7 +277,7 @@ function partition(env) {
continue;
}
const value = entry.value ?? '';
- const verdict = classify(name);
+ const verdict = classify(name, value);
if (!verdict.secret) {
(verdict.review ? review : config).push({ name, reason: verdict.reason });
continue;
@@ -412,7 +425,7 @@ function reportEndState(after, migratedNames) {
else if (!entry.valueFrom?.secretKeyRef) problems.push(`${name}: neither a literal nor a secretKeyRef`);
}
const leftoverLiterals = after.env
- .filter((e) => e.value && classify(e.name).secret)
+ .filter((e) => e.value && classify(e.name, e.value).secret)
.map((e) => e.name);
const servingRevision = after.traffic.find((t) => Number(t.percent) === 100);
const trafficOk = Boolean(servingRevision) && (servingRevision.latestRevision || servingRevision.revisionName === after.latestReady);
diff --git a/tests/migrate-plaintext-secrets.test.js b/tests/migrate-plaintext-secrets.test.js
index 1da9e9239..4eda62c73 100644
--- a/tests/migrate-plaintext-secrets.test.js
+++ b/tests/migrate-plaintext-secrets.test.js
@@ -9,7 +9,7 @@
// docs/ops/gcp-production.md).
import { describe, it, expect } from 'vitest';
-import { classify, defaultSecretName, mapLimit } from '../scripts/migrate-plaintext-secrets.mjs';
+import { classify, defaultSecretName, mapLimit, urlCarriesCredential } from '../scripts/migrate-plaintext-secrets.mjs';
describe('credential classifier', () => {
it('treats the wallet secret keys as credentials', () => {
@@ -57,11 +57,26 @@ describe('credential classifier', () => {
}
});
- it('flags a provider URL for a human call instead of filing it as public config', () => {
- for (const name of ['SOLANA_RPC_URL', 'UPSTASH_REDIS_REST_URL', 'HELIUS_RPC_ENDPOINT']) {
- const verdict = classify(name);
- expect(verdict.secret, name).toBe(false);
- expect(verdict.review, name).toBe(true);
+ // A URL's name says nothing about whether it carries a key, so the value
+ // decides. Every one of the 19 URL vars on production was checked this way on
+ // 2026-09-02 and only DATABASE_URL carried a credential.
+ it('leaves a provider URL alone when its value carries no credential', () => {
+ for (const [name, value] of [
+ ['SOLANA_RPC_URL', 'https://rpc.example.com/v2/abc'],
+ ['UPSTASH_REDIS_REST_URL', 'http://10.128.15.228'],
+ ['GCP_STYLIZE_URL', 'https://stylize-abc-uc.a.run.app'],
+ ]) {
+ expect(classify(name, value).secret, name).toBe(false);
+ }
+ });
+
+ it('migrates a provider URL that does carry one', () => {
+ for (const [name, value] of [
+ ['SOLANA_RPC_URL', 'https://rpc.example.com/?api-key=abc123'],
+ ['AGENT_WALLET_RPC_URL', 'https://eth.example.com/v2?apiKey=zzz'],
+ ['LIQUIDATION_COLLECTOR_URL', 'https://user:[email protected]/hook'],
+ ]) {
+ expect(classify(name, value).secret, name).toBe(true);
}
});
@@ -108,3 +123,30 @@ describe('mapLimit', () => {
expect(await mapLimit([], 4, async () => 'never')).toEqual([]);
});
});
+
+describe('urlCarriesCredential', () => {
+ it('finds a key in the query string under any spelling', () => {
+ for (const v of [
+ 'https://x.example/?api-key=a',
+ 'https://x.example/?api_key=a',
+ 'https://x.example/?apikey=a',
+ 'https://x.example/?token=a',
+ 'https://x.example/path?foo=1&secret=a',
+ 'https://x.example/?ACCESS-KEY=a',
+ ]) {
+ expect(urlCarriesCredential(v), v).toBe(true);
+ }
+ });
+
+ it('finds a credential in the userinfo, which is how a database URL carries one', () => {
+ expect(urlCarriesCredential('postgres://user:pw@host/db')).toBe(true);
+ });
+
+ // A path segment that merely looks key-shaped is not a query parameter, and an
+ // empty parameter carries nothing.
+ it('does not fire on a plain URL', () => {
+ for (const v of ['https://x.example/v2/abcdef', 'http://10.128.15.228', 'https://x.example/?key=', '']) {
+ expect(urlCarriesCredential(v), JSON.stringify(v)).toBe(false);
+ }
+ });
+});