mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 18:40:37 +08:00
fix: block case-variant secret paths and task runner env overrides
This commit is contained in:
1 parent
b49b0b63e6
commit
a23c5195ec
5 files changed
+46
-2
No files matched your search
@@ -24,8 +24,11 @@ export function resolveFileAccess(
|
||||
const resolvedRoot = path.resolve(root);
|
||||
const target = path.resolve(resolvedRoot, ...parts);
|
||||
if (target === resolvedRoot || !isWithin(resolvedRoot, target)) return '';
|
||||
// File systems such as default APFS can resolve a differently cased spelling
|
||||
// of the same entry. Check every protected name without case sensitivity.
|
||||
const blockedNames = new Set(blacklist.map((part) => part.toLowerCase()));
|
||||
const isBlocked = (relative: string) =>
|
||||
relative.split(path.sep).some((part) => blacklist.includes(part));
|
||||
relative.split(path.sep).some((part) => blockedNames.has(part.toLowerCase()));
|
||||
if (isBlocked(path.relative(resolvedRoot, target))) return '';
|
||||
try {
|
||||
const realRoot = fs.realpathSync(resolvedRoot);
|
||||
|
||||
@@ -7,6 +7,25 @@ const reservedNames = new Set([
|
||||
'TASK_BEFORE',
|
||||
'TASK_AFTER',
|
||||
'WORK_DIR',
|
||||
'TASK_SHELL_PARAMS',
|
||||
'SCRIPT_PARAMS',
|
||||
'WHICH_PROGRAM',
|
||||
'ISJSORPYTHONFILE',
|
||||
'EXPORTED_VARIABLES',
|
||||
'FOUND_DOUBLE_DASH',
|
||||
'LOG_DIR',
|
||||
'LOG_PATH',
|
||||
'ID',
|
||||
'BEGIN_TIMESTAMP',
|
||||
'TIME_FORMAT',
|
||||
'MTIME_FORMAT',
|
||||
'IS_MACOS',
|
||||
'RANDOMDELAY',
|
||||
'RANDOMDELAYFILEEXTENSIONS',
|
||||
'RANDOMDELAYIGNOREDMINUTES',
|
||||
'COMMAND_TIMEOUT_TIME',
|
||||
'SET_U_ON',
|
||||
'_TASK_EXIT_CODE',
|
||||
'PATH',
|
||||
'HOME',
|
||||
'SHELL',
|
||||
@@ -40,6 +59,7 @@ export function isAllowedTaskEnvName(name: unknown): name is string {
|
||||
const upper = name.toUpperCase();
|
||||
return (
|
||||
!reservedNames.has(upper) &&
|
||||
!upper.startsWith('BASH_') &&
|
||||
!upper.startsWith('QL') &&
|
||||
!upper.startsWith('FILE_') &&
|
||||
!upper.startsWith('DIR_') &&
|
||||
|
||||
@@ -57,6 +57,16 @@ test('environment API rejects execution controls and legacy rows stay out of tas
|
||||
{ id: 7, name: 'SAFE_VALUE', value: 'kept' },
|
||||
{ id: 8, name: 'bad\nname', value: 'untrusted' },
|
||||
{ id: 9, name: 'work_dir', value: '/tmp/untrusted' },
|
||||
{ id: 10, name: 'task_shell_params', value: 'other.sh' },
|
||||
{ id: 11, name: 'which_program', value: 'bash' },
|
||||
{ id: 12, name: 'script_params', value: 'other.sh' },
|
||||
{ id: 13, name: 'LOG_DIR', value: '../../config' },
|
||||
{ id: 14, name: 'EXPORTED_VARIABLES', value: 'PATH' },
|
||||
{ id: 15, name: 'begin_timestamp', value: 'a[$(printf BAD)]' },
|
||||
{ id: 16, name: 'is_macos', value: 'a[$(printf BAD)]' },
|
||||
{ id: 17, name: 'RandomDelayIgnoredMinutes', value: 'a[$(printf BAD)]' },
|
||||
{ id: 18, name: 'ID', value: '999' },
|
||||
{ id: 19, name: 'BASH_XTRACEFD', value: '2' },
|
||||
];
|
||||
const Env = load(path.resolve('back/services/env.ts'), {
|
||||
typedi: decorators,
|
||||
@@ -87,6 +97,10 @@ test('environment API rejects execution controls and legacy rows stay out of tas
|
||||
|
||||
for (const name of [
|
||||
'task_before', 'PREV_NODE_OPTIONS', 'GIT_SSH_COMMAND', 'work_dir',
|
||||
'task_shell_params', 'which_program', 'script_params', 'LOG_DIR',
|
||||
'EXPORTED_VARIABLES',
|
||||
'begin_timestamp', 'is_macos', 'RandomDelayIgnoredMinutes', 'ID',
|
||||
'BASH_XTRACEFD',
|
||||
]) {
|
||||
await assert.rejects(
|
||||
service.create([
|
||||
@@ -121,7 +135,7 @@ test('environment API rejects execution controls and legacy rows stay out of tas
|
||||
for (const contents of Object.values(output)) {
|
||||
assert.doesNotMatch(
|
||||
contents,
|
||||
/task_before|NODE_OPTIONS|GIT_SSH_COMMAND|PATH|work_dir/,
|
||||
/task_before|NODE_OPTIONS|GIT_SSH_COMMAND|PATH|work_dir|task_shell_params|which_program|script_params|LOG_DIR|EXPORTED_VARIABLES|begin_timestamp|is_macos|RandomDelayIgnoredMinutes|ID|BASH_XTRACEFD/,
|
||||
);
|
||||
assert.match(contents, /SAFE_VALUE/);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,9 @@ for (const customData of [false, true]) {
|
||||
);
|
||||
for (const name of [
|
||||
'token.json',
|
||||
'TOKEN.JSON',
|
||||
'grpc/client.key',
|
||||
'Grpc/client.key',
|
||||
'secret-link',
|
||||
'data/scripts/secret-link',
|
||||
'data/scripts/../config/token.json',
|
||||
@@ -181,7 +183,9 @@ test('log APIs allow configuration-like names while retaining directory boundari
|
||||
fs.writeFileSync(hidden, 'hidden task command');
|
||||
for (const values of [
|
||||
{ path: '.tmp', file: 'own_user.list', filename: 'own_user.list' },
|
||||
{ path: '.TMP', file: 'own_user.list', filename: 'own_user.list' },
|
||||
{ path: '', file: '.tmp/own_user.list', filename: '.tmp/own_user.list' },
|
||||
{ path: '', file: '.Tmp/own_user.list', filename: '.Tmp/own_user.list' },
|
||||
]) {
|
||||
for (const [method, route] of [
|
||||
['get', '/detail'],
|
||||
|
||||
@@ -24,11 +24,14 @@ test('file access enforces directory boundaries, blacklist descendants and symli
|
||||
'../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(
|
||||
|
||||
Reference in new issue
Block a user