Skip to content

fix: remove hardcoded secret in useAiAgent.ts (CWE-798) - #635

Closed
anupamme wants to merge 1 commit into
v0l:mainfrom
anupamme:fix-repo-snort-remove-hardcoded-ai-api-key
Closed

anupamme wants to merge 1 commit into
v0l:mainfrom
anupamme:fix-repo-snort-remove-hardcoded-ai-api-key

Conversation

@anupamme

Copy link
Copy Markdown

The useAiAgent.ts file contains hardcoded API credentials embedded directly in the client-side JavaScript bundle. The AI_CONFIG object contains a hardcoded API key '[REDACTED]' which will be exposed to anyone who inspects the bundled application code through browser DevTools or by downloading and analyzing the JavaScript bundle. The affected code is packages/app/src/Hooks/useAiAgent.ts:45. This change is the fix I would apply.

Reference: CWE-798

What changed

  • packages/app/src/Hooks/useAiAgent.ts

Verification

No automated check could be run against this repository, so this change is unverified beyond review. Please treat it as a suggestion.

Regression test

The security boundary is maintained under adversarial input

Test
import * as fs from "fs";
import * as path from "path";

describe("AI configuration must not expose hardcoded API credentials in source code", () => {
  const sourceFilePath = path.resolve(__dirname, "../../packages/app/src/Hooks/useAiAgent.ts");

  const sensitivePatterns = [
    { name: "hardcoded API key literal", pattern: /apiKey\s*:\s*["']sk_[a-zA-Z0-9]+["']/ },
    { name: "hardcoded secret value", pattern: /[REDACTED]/ },
    { name: "any hardcoded secret pattern", pattern: /apiKey\s*:\s*["'][^"']+["']/ },
  ];

  test.each(sensitivePatterns)("must not contain $name in source file", ({ pattern }) => {
    const sourceContent = fs.readFileSync(sourceFilePath, "utf-8");
    expect(pattern.test(sourceContent)).toBe(false);
  });

  test("API key must reference environment variable or secure runtime source", () => {
    const sourceContent = fs.readFileSync(sourceFilePath, "utf-8");
    const hasSecurePattern = /apiKey\s*:\s*(process\.env\.|import\.meta\.env\.)/.test(sourceContent);
    expect(hasSecurePattern).toBe(true);
  });
});

Automated security fix by OrbisAI Security

Automated security fix generated by OrbisAI Security
@v0l

v0l commented Sep 25, 2026

Copy link
Copy Markdown
Owner

Intentional

@v0l v0l closed this Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants