Skip to content

Commit df5e2f5

Browse files
author
skullcmd
committed
fix(security): resolve CodeQL high/medium code-scanning alerts
- dataManager: stop logging API key fragments in key-preservation warnings; log a non-reversible hashToken() prefix instead (js/clear-text-logging #80, #81). - dataManager: drop no-op .replace('T','T')/.replace('Z','Z') from the snapshot timestamp (js/identity-replacement #78, #79). - openaiProviderSelection: remove bypassable URL-substring host check in the Gemini permanent-auth-failure classifier; the function is already guarded by isGeminiLikeProviderId, so permission_denied alone suffices (js/incomplete-url-substring-sanitization #82).
1 parent b808863 commit df5e2f5

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

apps/api/modules/dataManager.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
33
import redis, { redisReadyPromise, Redis } from './db.js';
4+
import { hashToken } from './redaction.js';
45

56
const BunRuntime = (globalThis as any).Bun;
67
const HAS_BUN_FILE_IO =
@@ -821,7 +822,7 @@ class DataManager {
821822
if (keys.length === 0) return '';
822823
const preview = keys
823824
.slice(0, 5)
824-
.map(apiKey => `${apiKey.slice(0, 8)}...${apiKey.slice(-6)}`);
825+
.map(apiKey => `#${hashToken(apiKey).slice(0, 8)}`);
825826
return `${keys.length} key${keys.length === 1 ? '' : 's'} (${preview.join(', ')}${keys.length > preview.length ? ', ...' : ''})`;
826827
}
827828

@@ -901,9 +902,7 @@ class DataManager {
901902
await ensureDir(keySnapshotDir);
902903
const timestamp = new Date(now)
903904
.toISOString()
904-
.replace(/[-:.]/g, '')
905-
.replace('T', 'T')
906-
.replace('Z', 'Z');
905+
.replace(/[-:.]/g, '');
907906
const snapshotPath = path.join(
908907
keySnapshotDir,
909908
`keys-${timestamp}.json`

apps/api/modules/openaiProviderSelection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ function hasRecentGeminiCatalogAuthFailureSignal(provider: LoadedProviderData):
681681
lastError.includes('your project has been denied access') ||
682682
lastError.includes('project has been denied access') ||
683683
lastError.includes('accessnotconfigured') ||
684-
(lastError.includes('permission_denied') && lastError.includes('generativelanguage.googleapis.com')) ||
684+
lastError.includes('permission_denied') ||
685685
lastError.includes('service_disabled') ||
686686
lastError.includes('gemini_project_auth_failure')
687687
);

0 commit comments

Comments
 (0)