mirror of
https://github.com/whyour/qinglong.git
synced 2026-11-30 16:27:21 +08:00
* fix(security): restrict task environment controls and app scopes * fix(security): preserve legacy scopes and add read-only access * feat(security): add read-only scopes for remaining resources * fix(security): reject apps scope grants in app API * fix(security): protect system app and task file boundaries * fix: block case-variant secret paths and task runner env overrides
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
const assert = require('node:assert/strict');
|
|
const test = require('node:test');
|
|
const fs = require('node:fs');
|
|
const os = require('node:os');
|
|
const path = require('node:path');
|
|
const load = require('../helpers/load-security-module.cjs');
|
|
const { resolveFileAccess } = load(
|
|
path.join(__dirname, '../../back/shared/fileAccess.ts'),
|
|
);
|
|
|
|
test('file access enforces directory boundaries, blacklist descendants and symlinks', (t) => {
|
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-file-security-'));
|
|
t.after(() => fs.rmSync(tmp, { recursive: true, force: true }));
|
|
const root = path.join(tmp, 'config');
|
|
fs.mkdirSync(path.join(root, 'grpc'), { recursive: true });
|
|
fs.mkdirSync(path.join(tmp, 'config-other'));
|
|
fs.writeFileSync(path.join(root, 'normal.txt'), 'normal');
|
|
fs.writeFileSync(path.join(root, 'grpc', 'client.key'), 'test-only');
|
|
fs.symlinkSync(path.join(tmp, 'config-other'), path.join(root, 'outside'));
|
|
fs.symlinkSync(path.join(root, 'grpc'), path.join(root, 'alias'));
|
|
fs.symlinkSync(path.join(root, 'normal.txt'), path.join(root, 'safe-link'));
|
|
fs.symlinkSync(path.join(tmp, 'missing'), path.join(root, 'dangling'));
|
|
for (const input of [
|
|
'../config-other/secret',
|
|
'/etc/passwd',
|
|
'grpc/client.key',
|
|
'GRPC/client.key',
|
|
'alias/client.key',
|
|
'outside/new.txt',
|
|
'dangling',
|
|
'auth.json',
|
|
'AUTH.JSON',
|
|
'nested/auth.json',
|
|
'nested/Auth.Json',
|
|
'',
|
|
]) {
|
|
assert.equal(
|
|
resolveFileAccess(root, [input], ['grpc', 'auth.json']),
|
|
'',
|
|
input,
|
|
);
|
|
}
|
|
for (const input of ['normal.txt', 'safe-link', 'new-dir/new.txt']) {
|
|
assert.equal(
|
|
resolveFileAccess(root, [input], ['grpc']),
|
|
path.join(root, input),
|
|
input,
|
|
);
|
|
}
|
|
});
|