mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-03 10:18:18 +00:00
`ousast scan .` through ops/shell/ousast.sh with a native install scanned the wrong tree. The native path changed into the checkout before it passed the arguments on, so `.` was the OpenUltraSAST checkout and a relative file name was looked up there. The eighth session showed it with a stub interpreter in place of `.venv/bin/python` (`cwd=/tmp/opencode/s8_fakehome args=-m openultrasast.cli scan .`). The check also looked for `joern-parse` only, while the batch queries run `joern`: with `joern-parse` alone on PATH every batch query failed and a standard scan still exited 0 (2026-11-26, 14 findings where the working launcher gives 15). The native path now runs the checkout's interpreter by its absolute path, in the caller's directory, as the container path does, and it is taken only when `joern` is on PATH as well. So `.`, relative names and relative options mean the caller's files. The reviewer found, and a run confirmed, what dropping the `cd` brings: `-m` alone puts the working directory first on the interpreter's path, so a file of the scanned tree could stand in for a module the CLI imports (a `json.py` in the caller's directory: `ousast --help` printed SHADOW-EXECUTED and exited 3). The interpreter is started with `-P`, which keeps that directory off the path; the flag needs Python 3.11, the project's floor (pyproject.toml). Changes a caller sees, beyond the one the decision named: - The checkout's .env is no longer read on the native path; the CLI reads .env from the working directory, which is now the caller's. ops/README.md says so. - `ousast pairs` and `ousast repos` no longer find their defaults outside the checkout, because `benchmarks/` is read relative to the working directory. Measured for `pairs`: through the wrapper natively, and on the container path, `pairs --slice vibe-py` ends with "pair catalog is not a file: benchmarks/pairs/catalog.toml", exit 1, so the container path already behaved this way. `repos` by reading. Run from the checkout root they find their defaults again (by reading; not run). The header's `ousast pairs --slice vibe-py` example is removed. This is a reading the maintainer may correct. - The message for a machine without Docker names both executables. Tests: the new tests/test_shell_wrapper.py runs the wrapper by bash with a stub of the interpreter, `joern`, `joern-parse` and `docker` ahead of /usr/bin and /bin on PATH. Its two tests failed before the change (2 failed: the interpreter ran in the fake checkout, and the native path was taken without `joern`), and the first failed again until `-P` was passed (1 failed). With the real venv and Joern 4.0.625 on PATH, from a directory without .env: `ousast scan examples --mode quick` on a fresh copy of libpng's contrib/examples gives file_targets=4, findings=4, exit 0, before and after the flag, the figures of the eighth session. The eight tests of tests/test_docs_site.py and tests/test_removed_plane_references.py pass, `mkdocs build --strict` exits 0, ruff format, ruff check, mypy, the three gates and compileall pass, and the gates print what they printed before the change. An independent reviewer approved the change in the second round; its two findings of the first round led to the `-P` flag and to the removal of the header example. Found by the reviewer and left alone, outside this decision: the background child of `ousast pre-push` (src/openultrasast/push/background.py) starts the CLI with `-m` and without `-P`, from the pushed repository.
85 lines
3.9 KiB
Bash
85 lines
3.9 KiB
Bash
# OpenUltraSAST as a local command. Source this from ~/.bashrc or ~/.zshrc:
|
|
#
|
|
# source /path/to/OpenUltraSAST/ops/shell/ousast.sh
|
|
#
|
|
# Then use it like any other linter, from any directory:
|
|
#
|
|
# ousast scan .
|
|
# ousast scan src/api
|
|
#
|
|
# Docker is an implementation detail on purpose. The engine is a JVM and ~2 GB of Joern, and a contributor
|
|
# evaluating this tool should not have to install either to try it. What they get instead is a command.
|
|
#
|
|
# The one thing worth knowing: your working directory is mounted READ-ONLY, and findings are written to
|
|
# ./.ousast, which is the only writable mount. A tool that reads your source to tell you about it has no
|
|
# business being able to change it.
|
|
|
|
# Resolve this script's own location so the function works from anywhere, under bash or zsh.
|
|
if [ -n "${BASH_SOURCE[0]:-}" ]; then
|
|
_OUSAST_HOME="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
elif [ -n "${(%):-%N}" ] 2>/dev/null; then
|
|
_OUSAST_HOME="$(cd "$(dirname "${(%):-%N}")/../.." && pwd)"
|
|
fi
|
|
export OUSAST_HOME="${OUSAST_HOME:-$_OUSAST_HOME}"
|
|
|
|
ousast() {
|
|
local compose="$OUSAST_HOME/docker-compose.yml"
|
|
if [ ! -f "$compose" ]; then
|
|
echo "ousast: cannot find $compose (set OUSAST_HOME to the checkout)" >&2
|
|
return 1
|
|
fi
|
|
|
|
# A native install wins when it is there: it is faster, and someone who installed Joern deliberately
|
|
# should not be quietly routed through a container. It runs in the caller's directory, as the container
|
|
# does, so `.`, relative names and relative options mean the caller's files. -P keeps that directory off
|
|
# the interpreter's path, where a file of it could stand in for a module the CLI imports. Joern is looked
|
|
# for as well: the batch queries run `joern`, and with `joern-parse` alone every one fails while the scan
|
|
# still exits 0.
|
|
if [ "${OUSAST_PREFER_NATIVE:-1}" = "1" ] && command -v joern >/dev/null 2>&1 \
|
|
&& command -v joern-parse >/dev/null 2>&1 && [ -x "$OUSAST_HOME/.venv/bin/python" ]; then
|
|
"$OUSAST_HOME/.venv/bin/python" -P -m openultrasast.cli "$@"
|
|
return $?
|
|
fi
|
|
|
|
if ! command -v docker >/dev/null 2>&1; then
|
|
echo "ousast: docker is not installed, and no local joern and joern-parse were found" >&2
|
|
return 1
|
|
fi
|
|
|
|
# Build once, silently, the first time. A first run that prints a wall of build output and then works is
|
|
# worse than one that pauses and explains itself.
|
|
if ! docker image inspect "openultrasast:${OUSAST_VERSION:-dev}" >/dev/null 2>&1; then
|
|
echo "ousast: building the analysis image once (this pulls ~2 GB of engine; later runs are instant)" >&2
|
|
( cd "$OUSAST_HOME" && docker compose build ) || return 1
|
|
fi
|
|
|
|
# Rewrite paths that live under the current directory to their mounted equivalent, so `ousast scan src/api`
|
|
# means what the user expects. Anything outside the mount is left alone and warned about rather than
|
|
# silently rewritten into a path the container cannot see.
|
|
local args=() a abs
|
|
for a in "$@"; do
|
|
if [ -e "$a" ]; then
|
|
abs="$(cd "$(dirname "$a")" 2>/dev/null && pwd)/$(basename "$a")"
|
|
case "$abs" in
|
|
"$PWD") args+=("/target") ;;
|
|
"$PWD"/*) args+=("/target${abs#"$PWD"}") ;;
|
|
*) echo "ousast: $a is outside $PWD and is not mounted; passing it through unchanged" >&2
|
|
args+=("$a") ;;
|
|
esac
|
|
else
|
|
args+=("$a")
|
|
fi
|
|
done
|
|
|
|
mkdir -p "$PWD/.ousast"
|
|
TARGET="$PWD" OUSAST_REPORTS="$PWD/.ousast" \
|
|
OUSAST_NETWORK="${OUSAST_NETWORK:-none}" \
|
|
docker compose -f "$compose" run --rm ousast "${args[@]}"
|
|
}
|
|
|
|
# The LLM judge needs the network and a key; without them the model layer still entails and only the
|
|
# `suspicion` band goes unasked. This makes that opt-in explicit rather than a surprise.
|
|
ousast-with-judge() {
|
|
OUSAST_NETWORK=bridge ousast "$@"
|
|
}
|