mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-16 03:09:33 +01:00
fix: keep credential files out of the file routes and Discord uploads (release review)
The Discord bot token was readable through the attachment routes, because discord.json was not on the sensitive list, and so were webhook.json, custom-model-hosts.json and the generated custom-model configs. Config backups were the wider gap: a dated copy of users.json or settings.json matched none of the name-anchored patterns. All are blocked now. `codeman notify --file` relied on folder confinement alone, which holds nothing back when a tab's folder is the home directory, and it would also post a workspace .env. It now applies the attachment blocklist to the real path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
126d967ba3
commit
4276b53a8f
7 files changed
+57
-6
No files matched your search
@@ -5,7 +5,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { mkdirSync, mkdtempSync, rmSync, statSync, symlinkSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { createRouteTestHarness } from './_route-test-utils.js';
|
||||
import { _resetNotifyBuckets, registerDiscordRoutes } from '../../src/web/routes/discord-routes.js';
|
||||
import { DiscordBridge, discordConfigPath, readDiscordConfig, type DiscordFetch } from '../../src/discord-bridge.js';
|
||||
@@ -286,6 +286,32 @@ describe('discord-notify with a file', () => {
|
||||
bridge.stop();
|
||||
});
|
||||
|
||||
it.each([
|
||||
['a .env file', () => ['.env', 'TOKEN=x']],
|
||||
['a private key under .ssh', () => ['.ssh/id_ed25519', 'key']],
|
||||
['Codeman state with the bot token', () => ['.codeman/discord.json', '{}']],
|
||||
])('refuses %s even inside the session folder, as with a home directory', async (_n, entry) => {
|
||||
const [rel, body] = entry();
|
||||
mkdirSync(dirname(join(work, rel)), { recursive: true });
|
||||
writeFileSync(join(work, rel), body);
|
||||
const { app, bridge } = await ready();
|
||||
const res = await post(app, join(work, rel));
|
||||
expect(res.statusCode).toBe(400);
|
||||
expect(res.json().error).toMatch(/credentials/);
|
||||
expect(fetchImpl.mock.calls.some((c) => c[1].body instanceof FormData)).toBe(false);
|
||||
bridge.stop();
|
||||
});
|
||||
|
||||
it('refuses a symlink inside the folder that points at a blocked file', async () => {
|
||||
writeFileSync(join(work, '.env'), 'TOKEN=x');
|
||||
symlinkSync(join(work, '.env'), join(work, 'notes.txt'));
|
||||
const { app, bridge } = await ready();
|
||||
const res = await post(app, join(work, 'notes.txt'));
|
||||
expect(res.statusCode).toBe(400);
|
||||
expect(fetchImpl.mock.calls.some((c) => c[1].body instanceof FormData)).toBe(false);
|
||||
bridge.stop();
|
||||
});
|
||||
|
||||
it('refuses to send when the session folder is not a directory it can probe', async () => {
|
||||
const { app, ctx, bridge } = await ready();
|
||||
(ctx.sessions.get('test-session-1') as unknown as { workingDir: string }).workingDir = join(work, 'run.log');
|
||||
|
||||
@@ -93,6 +93,14 @@ describe('isSensitivePath', () => {
|
||||
// contents included): 0600 and kept out of /api/search like intents.json.
|
||||
['codeman edit history store', `${HOME}/.codeman/edit-history/s1.json`],
|
||||
['codeman edit history on a named instance', `${HOME}/.codeman-beta/edit-history/s1.json`],
|
||||
// Credentials outside settings.json, and the backups that copy all of these.
|
||||
['codeman Discord bot token', `${HOME}/.codeman/discord.json`],
|
||||
['codeman Discord token on a named instance', `${HOME}/.codeman-beta/discord.json`],
|
||||
['codeman webhook URL', `${HOME}/.codeman/webhook.json`],
|
||||
['codeman custom endpoint API keys', `${HOME}/.codeman/custom-model-hosts.json`],
|
||||
['a generated custom model config', `${HOME}/.codeman/custom-model-configs/s1/opencode.json`],
|
||||
['a backed-up user list', `${HOME}/.codeman/backups/config/cfg-20261104-120000/users.json`],
|
||||
['a backed-up settings file', `${HOME}/.codeman/backups/config/cfg-20261104-120000/settings.json`],
|
||||
];
|
||||
|
||||
it.each(blocked)('blocks the %s', (_label, path) => {
|
||||
|
||||
Reference in new issue
Block a user