Commit Graph
3 Commits
Author SHA1 Message Date
Lauri Ojansivu 2b65b713a0 Tests: no path handed to a shell at all, CodeQL alerts #602 and #603.
The fix for #601 passed the paths to `bash -c` as arguments ("$1",
"$2") instead of pasting them into the script. That is safe in itself,
but it still hands a temporary or checkout path to a shell, and CodeQL
flagged js/shell-command-injection-from-environment again on the two
umask tests in tests/releaseDownloads.test.cjs. Those tests no longer
use a shell: fetch.sh runs as bash's program with its arguments, the
umask is set on the test's own process around the call and put back,
and `chmod +x` is fs.chmodSync. tests/macosSandbox.test.cjs, fixed the
same way for #601, now runs ls and touch as programs of sandbox-exec,
each path an argument.

The guard (tests/testShellPathsFromEnv.test.cjs) now also refuses any
value given to a shell's -c script as an argument - spawned or as a
wrapper's program - and the one other test that did so,
tests/dbConformanceWiring.test.cjs, passes its value in the environment.
Run against the files as they were, it names all three; its pattern
takes a backslash only as an escape, so a long file cannot make it
backtrack.

The findings were in tests, not in WeKan, so there is no attempt to
show in Admin Panel -> Problems.

Thanks to GitHub CodeQL and xet7 !
2026-11-11 03:44:13 +02:00
Lauri Ojansivu d482856e03 Tests: no path is quoted into a bash -c script, CodeQL alert #601 and its siblings.
CodeQL flagged js/shell-command-injection-from-environment (CWE-78/88) in
tests/npmRetry.test.cjs: its bash -c script set
node_bin=${JSON.stringify(prog)} and ran bash ${JSON.stringify(script)},
pasting a path under the temporary directory and one under the checkout
into the script text. JSON's quotes are not the shell's: a path with $(,
a backtick or $ would change the command. The paths now go in through
the environment ("$NODE_BIN", "$NPM_RETRY_SCRIPT"), so the script is a
constant - and NODE_BIN is not node_bin, so the test still shows the
unbound variable it exists to show.

The guard written for alerts #549 and #550 (tests/testShellPathsFromEnv
.test.cjs) only knew `source "${path}"`. It now refuses any value quoted
into a -c script - "${...}" or ${JSON.stringify(...)} - across the tests,
while a script built from the test's own snippets stays allowed; with
the fixes taken away it names every offender. It found the same fault in
two more places, fixed as arguments ("$1", "$2"):
tests/releaseDownloads.test.cjs, which quoted fetch.sh and a temporary
file into its umask tests, and tests/macosSandbox.test.cjs, which quoted
the home and temporary paths into its sandbox probe.

The finding was in tests, not in WeKan, so there is no attempt to show
in Admin Panel -> Problems.

Thanks to GitHub CodeQL and xet7 !
2026-11-11 00:37:39 +02:00
Lauri Ojansivu 433e58a618 Tests pass shell paths through the environment, not into bash -c scripts.
GitHub CodeQL code scanning alerts #549 and #550
(js/shell-command-injection-from-environment): tests/snapSettingsKeys and
tests/snapSocketDenied ran `bash -c` with a script that interpolated an
absolute path built from __dirname (`source "${configPath}"`,
`source "${helper}"`). A checkout path containing a quote, `$(` or a
backtick would change the command that runs. tests/linuxPackageManagers
and tests/snapCaddyNofile6552 had the same shape without an alert yet.

All four now pass the path (and the soft limit, and the wekan-control
function under test) in environment variables, so every script text is
constant. tests/testShellPathsFromEnv.test.cjs fails on any test that
sources an interpolated value, and checks it catches the flagged forms.
These are test files run on a developer machine or CI, so no attack can be
attempted against a running WeKan and nothing is logged in Admin Panel ->
Problems.

Thanks to GitHub CodeQL and xet7 !
2026-10-08 00:16:24 +03:00