fix(security): protect system app and task file boundaries

This commit is contained in:
whyour committed 2026-11-03 09:32:40 +08:00
1 parent 487b213dd8
commit b49b0b63e6
6 files changed
+52 -3

No files matched your search

+8 -2
View File
@@ -56,6 +56,7 @@ test('environment API rejects execution controls and legacy rows stay out of tas
{ id: 6, name: 'file_task_before', value: '/tmp/untrusted.sh' },
{ id: 7, name: 'SAFE_VALUE', value: 'kept' },
{ id: 8, name: 'bad\nname', value: 'untrusted' },
{ id: 9, name: 'work_dir', value: '/tmp/untrusted' },
];
const Env = load(path.resolve('back/services/env.ts'), {
typedi: decorators,
@@ -84,7 +85,9 @@ test('environment API rejects execution controls and legacy rows stay out of tas
service.getDb = async () => ({ id: 1, name: 'SAFE_VALUE', value: 'kept' });
service.updateDb = async () => { writes++; return {}; };
for (const name of ['task_before', 'PREV_NODE_OPTIONS', 'GIT_SSH_COMMAND']) {
for (const name of [
'task_before', 'PREV_NODE_OPTIONS', 'GIT_SSH_COMMAND', 'work_dir',
]) {
await assert.rejects(
service.create([
{ name: 'SAFE_VALUE', value: 'ok' },
@@ -116,7 +119,10 @@ test('environment API rejects execution controls and legacy rows stay out of tas
assert.equal(listed[0].securityBlocked, true);
assert.equal(listed[6].securityBlocked, false);
for (const contents of Object.values(output)) {
assert.doesNotMatch(contents, /task_before|NODE_OPTIONS|GIT_SSH_COMMAND|PATH/);
assert.doesNotMatch(
contents,
/task_before|NODE_OPTIONS|GIT_SSH_COMMAND|PATH|work_dir/,
);
assert.match(contents, /SAFE_VALUE/);
}
});
+16
View File
@@ -176,5 +176,21 @@ test('log APIs allow configuration-like names while retaining directory boundari
])
assert.equal((await invoke(method, route, values)).code, 403, filename);
}
const hidden = path.join(config.logPath, '.tmp', 'own_user.list');
fs.mkdirSync(path.dirname(hidden), { recursive: true });
fs.writeFileSync(hidden, 'hidden task command');
for (const values of [
{ path: '.tmp', file: 'own_user.list', filename: 'own_user.list' },
{ path: '', file: '.tmp/own_user.list', filename: '.tmp/own_user.list' },
]) {
for (const [method, route] of [
['get', '/detail'],
['post', '/download'],
['delete', '/'],
]) {
assert.equal((await invoke(method, route, values)).code, 403);
}
}
assert.equal(fs.readFileSync(hidden, 'utf8'), 'hidden task command');
assert.equal(fs.readFileSync(secret, 'utf8'), 'PANEL-SECRET');
});
+16
View File
@@ -397,6 +397,22 @@ for (const mutation of ['resetSecret', 'remove', 'update', 'create']) {
});
}
test('application mutations cannot change or expose the built-in system app', async (t) => {
const state = appsFixture(t);
for (const change of [
() => state.service.resetSecret(1),
() => state.service.update({ id: 1, name: 'system', scopes: ['crons'] }),
() => state.service.update({ id: 2, name: 'system', scopes: ['crons'] }),
() => state.service.remove([1, 2]),
]) {
await assert.rejects(change(), (error) => error.status === 403);
}
assert.equal(state.apps().length, 2);
assert.equal(state.apps()[0].client_secret, 'system-secret');
assert.equal(state.apps()[0].tokens[0].value, 'system-token');
assert.deepEqual(state.cached(), state.apps());
});
test('system initialization preserves active tokens while migrating dashboard scope', async (t) => {
const state = appsFixture(t);
await AppModel.update({ scopes: ['crons', 'system'] }, { where: { id: 1 } });