feat(backend): add plugin execution sandbox with SIGTERM→SIGKILL e, fixes- #326#399
Closed
samarthsugandhi wants to merge 1 commit into
Closed
feat(backend): add plugin execution sandbox with SIGTERM→SIGKILL e, fixes- #326#399samarthsugandhi wants to merge 1 commit into
samarthsugandhi wants to merge 1 commit into
Conversation
…lation, output cap, and POSIX resource limits
Owner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
SandboxConfig/SandboxViolation/run_sandboxedlayer insandbox_executor.pythat wraps every plugin subprocess with configurabletimeout enforcement, output byte-capping, and POSIX resource limits.
The existing
_execute_commandinexecutor.pyis replaced with a callto the sandbox, with zero changes to any other executor logic.
Closes #326.
Changes
New file —
backend/secuscan/sandbox_executor.pySandboxConfigdataclass:timeout_seconds,max_memory_mb,max_output_bytes,sigterm_grace_secondsSandboxViolationexception: carriesreason(timeout|memory_limit|output_limit) andoutput(partial output)run_sandboxed(): wrapsasyncio.create_subprocess_execwith:asyncio.wait_for()enforcingtimeout_secondsmax_output_byteswith drainpreexec_fnapplyingRLIMIT_AS+RLIMIT_CPUon Linux;skipped silently on macOS/Windows via
platform.system()guardsigterm_grace_seconds→ SIGKILL escalation-9/137detection for OS memory kills (Linux)_escalate_kill(): platform-safe SIGTERM→SIGKILL helperModified —
backend/secuscan/executor.py_execute_command()replaced: now delegates torun_sandboxed()SandboxViolationcaught: broadcaststerminated:{reason}statusevent, writes structured
error_messageto DB, logs audit eventexecute_task(): buildsSandboxConfigfrom plugin metadataoutput.sandboxkey with fallback to globalsettingsvalues,enabling per-plugin resource overrides without code changes
How to test
SECUSCAN_SANDBOX_TIMEOUT=5and scan a slow target —confirm task status shows
terminated:timeoutafter 5 secondsSECUSCAN_SANDBOX_MEMORY_MB=1— confirmterminated:memory_limiton a memory-heavy pluginGET /api/v1/audit— confirmsandbox_violationeventappears with correct
reasonin contextterminated:timeoutbadgerenders distinctly from generic failure
Notes
resource.setrlimitis Linux-only; aplatform.system()guardskips it on macOS/Windows — timeouts still apply on all platforms
SandboxConfigdefaults mirror existingsettings.sandbox_timeoutandsettings.sandbox_memory_mbvaluesasyncio,signal,resource,platform)Closes #326