Repository navigation
Description
Code Audit Report
All findings are reviewed for confidence before posting.
Please verify each finding before acting on it.
Repository: MoonshotAI/kimi-code
Findings: 6 issue(s) found β π 4 high Β· π‘ 1 medium Β· π΅ 1 low
1. π Invalid use of import.meta.dirname
| Field | Details |
|---|---|
| Severity | π High |
| Type | Bug |
| File | apps/kimi-code/tsdown.config.ts |
| Location | const appRoot = import.meta.dirname; |
| Confidence | 97% |
Problem:
Node's ES modules do not provide import.meta.dirname; the property is undefined. Consequently, appRoot becomes undefined, causing resolve(appRoot, 'src') to compute an incorrect path and break the build.
Suggested Fix:
Replace the line with a proper dirname resolution, e.g.:
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
const __filename = fileURLToPath(import.meta.url);
const appRoot = dirname(__filename);2. π Invalid use of import.meta.dirname
| Field | Details |
|---|---|
| Severity | π High |
| Type | Bug |
| File | apps/kimi-code/tsdown.native.config.ts |
| Location | const appRoot = import.meta.dirname; |
| Confidence | 98% |
Problem:
Node's ES module import.meta does not provide a 'dirname' property. Accessing import.meta.dirname returns undefined, causing 'appRoot' to be undefined. This leads to runtime errors when 'resolve(appRoot, "src")' is evaluated, breaking the configuration loading.
Suggested Fix:
Replace the line with a proper resolution of the directory, e.g.:
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const appRoot = __dirname;Then the alias can remain as alias: { '@': resolve(appRoot, 'src') }.
3. π Uncaught exception from listModelsFromHarness
| Field | Details |
|---|---|
| Severity | π High |
| Type | Bug |
| File | packages/acp-adapter/src/config-options.ts |
| Location | buildSessionConfigOptions |
| Confidence | 95% |
Problem:
The function calls await listModelsFromHarness(harness) without a try/catch. If listModelsFromHarness throws (e.g., due to a misbehaving harness), the promise rejects and the entire configβbuilding process fails, contradicting the comment that the helper is tolerant to stub harnesses and should resolve to an empty catalog.
Suggested Fix:
Wrap the call in a try/catch and default to an empty array on error:
let models: AcpModelEntry[] = [];
try {
models = await listModelsFromHarness(harness);
} catch (e) {
// Log the error if appropriate, but continue with an empty model list
console.warn('Failed to list models from harness, proceeding with empty catalog', e);
}4. π Missing default case leads to undefined return
| Field | Details |
|---|---|
| Severity | π High |
| Type | Bug |
| File | packages/acp-adapter/src/events-map.ts |
| Location | turnEndReasonToStopReason |
| Confidence | 96% |
Problem:
The function turnEndReasonToStopReason switches on reason but does not handle unexpected values. If a value outside the known TurnEndReason literals is passed at runtime, the function returns undefined, which violates the expected AcpStopReason type and can cause downstream failures when the caller assumes a valid stop reason string.
Suggested Fix:
Add a default case that returns a sensible fallback (e.g., 'end_turn') or throws an explicit error. Example:
export function turnEndReasonToStopReason(reason: TurnEndReason): AcpStopReason {
switch (reason) {
case 'completed':
return 'end_turn';
case 'cancelled':
return 'cancelled';
case 'failed':
return 'end_turn';
default:
// Fallback for unexpected values
return 'end_turn'; // or throw new Error(`Unexpected TurnEndReason: ${reason}`);
}
}5. π Potential XSS via untrusted model metadata
| Field | Details |
|---|---|
| Severity | π‘ Medium |
| Type | Security |
| File | packages/acp-adapter/src/config-options.ts |
| Location | buildModelOption |
| Confidence | 92% |
Problem:
The id, name, and description fields from AcpModelEntry are taken directly from the harness and embedded into the SessionConfigOption sent to the client. If the harness supplies malicious strings (e.g., containing HTML/JS), a client that renders these values without proper escaping could be vulnerable to reflected XSS.
Suggested Fix:
Sanitize or escape model fields before including them in the response. For example, use a utility to strip or encode HTML characters:
import { escapeHtml } from './utils';
export function buildModelOption(models: readonly AcpModelEntry[], currentBaseModelId: string): SessionConfigOption {
const options: SessionConfigSelectOption[] = models.map((model) => ({
value: escapeHtml(model.id),
name: escapeHtml(model.name),
...(model.description !== undefined ? { description: escapeHtml(model.description) } : {}),
}));
// ...rest unchanged
}6. π Incorrect filter condition prevents removal of mermaid dependencies
| Field | Details |
|---|---|
| Severity | π΅ Low |
| Type | Bug |
| File | docs/.vitepress/config.ts |
| Location | vite: { optimizeDeps: { include: mermaidOptimizeDeps.map((dep) => mermaid > ${dep}) }, ... } and subsequent filter block |
| Confidence | 95% |
Problem:
The code builds vite.optimizeDeps.include as strings like "mermaid > @braintree/sanitize-url" but later filters the array using mermaidOptimizeDeps.includes(dep). Since dep is a prefixed string, the includes check never matches, so the intended removal of mermaid dependencies never occurs. This is a logical bug that can leave unnecessary dependencies in the bundle.
Suggested Fix:
Adjust the filter to compare against the prefixed strings, e.g.: config.vite.optimizeDeps.include = config.vite.optimizeDeps.include.filter(dep => !mermaidOptimizeDeps.some(d => dep === mermaid > ${d}));
About this report
This report was generated using Llama 3.3 70B.
Only findings with β₯80% confidence are included.
False positives are possible β use your own judgment.
Activity
asmit25805 commentedon Jun 17, 2026
Thanks for taking a look and reviewing the report anyway! Completely understand. Feel free to disregard these if they're false positives or don't align with the current roadmap.