Ignore own process in root Node process check

This commit is contained in:
pdmarf
2026-04-17 22:55:36 +01:00
parent 75e1957a26
commit 9b35a0b338

View File

@@ -108,12 +108,18 @@ else
# Check if each root process is inside a Docker cgroup (normal) # Check if each root process is inside a Docker cgroup (normal)
while IFS= read -r proc; do while IFS= read -r proc; do
PID=$(echo "$proc" | awk '{print $2}') PID=$(echo "$proc" | awk '{print $2}')
CMD=$(cat /proc/"$PID"/cmdline 2>/dev/null | tr '\0' ' ' || echo 'unreadable')
# Skip this script's own process
if echo "$CMD" | grep -qF "npm-security-check.sh"; then
ok "PID $PID is this script running — not a threat"
continue
fi
CGROUP=$(cat /proc/"$PID"/cgroup 2>/dev/null | grep -c "docker" || true) CGROUP=$(cat /proc/"$PID"/cgroup 2>/dev/null | grep -c "docker" || true)
if [[ "$CGROUP" -gt 0 ]]; then if [[ "$CGROUP" -gt 0 ]]; then
ok "PID $PID runs as root but is inside a Docker container (normal)" ok "PID $PID runs as root but is inside a Docker container (normal)"
else else
warn "PID $PID is a root Node process outside Docker — review manually" warn "PID $PID is a root Node process outside Docker — review manually"
log " Command: $(cat /proc/"$PID"/cmdline 2>/dev/null | tr '\0' ' ' || echo 'unreadable')" log " Command: $CMD"
fi fi
done <<< "$ROOT_PROCS" done <<< "$ROOT_PROCS"
else else