mirror of
https://github.com/storytold/craft-common-actions.git
synced 2026-11-19 08:55:36 +00:00
security(freebsd): prevent shell injection through Cargo extra arguments (#56)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
11013609b1
commit
82b63dea97
3 files changed
+91
-8
No files matched your search
@@ -25,12 +25,12 @@ on:
|
||||
required: false
|
||||
default: "15.1-STABLE"
|
||||
cargo-test-extra-args:
|
||||
description: "Extra arguments to append to cargo test (optional)"
|
||||
description: "Extra arguments to append to cargo test (shell-style quoting, no shell expansion)"
|
||||
type: string
|
||||
required: false
|
||||
default: ""
|
||||
cargo-build-extra-args:
|
||||
description: "Extra arguments to append to cargo build (optional)"
|
||||
description: "Extra arguments to append to cargo build (shell-style quoting, no shell expansion)"
|
||||
type: string
|
||||
required: false
|
||||
default: ""
|
||||
@@ -69,6 +69,8 @@ jobs:
|
||||
matrix:
|
||||
arch: ${{ fromJSON(inputs.architectures != '' && inputs.architectures || ((github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && '["x86_64"]' || '["x86_64","aarch64"]')) }}
|
||||
env:
|
||||
CARGO_BUILD_EXTRA_ARGS: ${{ inputs.cargo-build-extra-args }}
|
||||
CARGO_TEST_EXTRA_ARGS: ${{ inputs.cargo-test-extra-args }}
|
||||
CARGO_HOME: /var/tmp/craft-cargo
|
||||
CARGO_TARGET_DIR: /var/tmp/craft-target
|
||||
CARGO_INCREMENTAL: 0
|
||||
@@ -92,7 +94,7 @@ jobs:
|
||||
cpu: 4
|
||||
mem: 12288
|
||||
copyback: false
|
||||
envs: "CARGO_HOME CARGO_TARGET_DIR CARGO_INCREMENTAL CARGO_BUILD_JOBS"
|
||||
envs: "CARGO_HOME CARGO_TARGET_DIR CARGO_INCREMENTAL CARGO_BUILD_JOBS CARGO_BUILD_EXTRA_ARGS CARGO_TEST_EXTRA_ARGS"
|
||||
prepare: |
|
||||
# Keep rustup/proxies outside the Cargo data cache.
|
||||
unset CARGO_HOME CARGO_TARGET_DIR
|
||||
@@ -209,7 +211,14 @@ jobs:
|
||||
chown -R craft-test "$CARGO_TARGET_DIR" "$CARGO_HOME" "$PWD"
|
||||
HOME=/home/craft-test RUSTUP_HOME=$rustup_home su -m craft-test -c 'sh -eu'
|
||||
}
|
||||
CARGO_PROFILE_DEV_DEBUG=0 cargo build --workspace --all-targets --locked ${{ inputs.cargo-build-extra-args }}
|
||||
# Keep argument data out of shell source, including the tester's shell below.
|
||||
CARGO_PROFILE_DEV_DEBUG=0 python3 - <<'PY'
|
||||
import os
|
||||
import shlex
|
||||
|
||||
os.execvp("cargo", ["cargo", "build", "--workspace", "--all-targets", "--locked",
|
||||
*shlex.split(os.environ["CARGO_BUILD_EXTRA_ARGS"])])
|
||||
PY
|
||||
if [ "${{ inputs.skip-tests }}" != "true" ]; then
|
||||
if [ "${{ matrix.arch }}" = aarch64 ]; then
|
||||
# The build above compiled every test target; an x86_64 guest cannot run them.
|
||||
@@ -222,7 +231,13 @@ jobs:
|
||||
CRAFT_CUSTOM_TESTS
|
||||
else
|
||||
as_tester <<'CRAFT_TESTS'
|
||||
CARGO_PROFILE_DEV_DEBUG=0 cargo test --workspace --locked ${{ inputs.cargo-test-extra-args }}
|
||||
CARGO_PROFILE_DEV_DEBUG=0 python3 - <<'PY'
|
||||
import os
|
||||
import shlex
|
||||
|
||||
os.execvp("cargo", ["cargo", "test", "--workspace", "--locked",
|
||||
*shlex.split(os.environ["CARGO_TEST_EXTRA_ARGS"])])
|
||||
PY
|
||||
CRAFT_TESTS
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user