Objective
Add security validation to the ApplyJqFilter function in pkg/cli/jq.go to prevent command injection, file reads, DoS attacks, and resource exhaustion from malicious jq filter expressions.
Context
Issue #14844 identified a high-severity security risk: the jq filter processing accepts arbitrary user input and passes it directly to exec.Command without validation. While Go's exec.Command prevents shell injection, jq itself has powerful features that can be exploited:
input function can read arbitrary files
- Recursive expressions can cause DoS
@sh formatter could enable downstream code execution
Approach
Implement multi-layered security hardening:
- Syntax Validation: Add filter syntax validation before execution
- Dangerous Function Detection: Block filters containing
input, debug, $__loc__
- Execution Timeouts: Add context with timeout (e.g., 30 seconds)
- Resource Limits: Consider memory/CPU limits if feasible
- Security Logging: Log filter validation attempts and rejections
Files to Modify
- Update:
pkg/cli/jq.go (lines 20-40) - Add validation logic to ApplyJqFilter
- Create:
pkg/cli/jq_test.go - Add security tests for malicious filters
- Optional: Create
pkg/security/jq_validator.go if validation becomes complex
Acceptance Criteria
AI generated by Plan Command for #14844
Objective
Add security validation to the
ApplyJqFilterfunction inpkg/cli/jq.goto prevent command injection, file reads, DoS attacks, and resource exhaustion from malicious jq filter expressions.Context
Issue #14844 identified a high-severity security risk: the jq filter processing accepts arbitrary user input and passes it directly to
exec.Commandwithout validation. While Go'sexec.Commandprevents shell injection, jq itself has powerful features that can be exploited:inputfunction can read arbitrary files@shformatter could enable downstream code executionApproach
Implement multi-layered security hardening:
input,debug,$__loc__Files to Modify
pkg/cli/jq.go(lines 20-40) - Add validation logic toApplyJqFilterpkg/cli/jq_test.go- Add security tests for malicious filterspkg/security/jq_validator.goif validation becomes complexAcceptance Criteria
input,debug,$__loc__are rejected with clear error messagesRelated to [sergo] Sergo Report: Documentation-Security-Naming - 2026-02-10 #14844