Skip to content

Improve security: redact sensitive evidence, tighten scope checks, secure persistence, and test coverage - #1

Closed
prithvee07 wants to merge 1 commit into
mainfrom
codex/learn-the-codebase
Closed

Improve security: redact sensitive evidence, tighten scope checks, secure persistence, and test coverage#1
prithvee07 wants to merge 1 commit into
mainfrom
codex/learn-the-codebase

Conversation

@prithvee07

Copy link
Copy Markdown
Owner

Motivation

  • Prevent secrets from leaking into logs, AI prompts, reports, or persistent state by centrally redacting common credential patterns and ensuring commands stored are sanitized.
  • Reduce attack surface from unsafe file permissions and TOCTOU windows by making session and report files/directories private and re-checking scope before executing external tools.
  • Harden XML parsing and scope validation to mitigate entity expansion, oversized input, DNS-rebinding, and special-address bypasses.

Description

  • Added utils/redaction.py and integrated redact_sensitive_text in core/workflow.py and when saving tool executions so raw tool evidence and analyst inputs have common credential patterns redacted.
  • Updated tools/base_tool.py so the logged/stored command is always the sanitized form returned by _sanitize_command_for_logging and never the raw executable arguments.
  • Hardened persistence: PentestMemory.save_state and workflow report/session save paths now create directories with mode 0o700 and create files with 0o600 via os.open/os.fchmod to avoid world-readable secrets.
  • Re-validate scope immediately before each tool execution and AI-decided tool run in core/workflow.py to reduce TOCTOU/DNS-rebinding windows.
  • Tightened utils/scope_validator.py blacklist behavior to block non-global addresses (including IPv6 ULA and IPv4 link-local) and explicit special names, and continue to resolve hostnames and check resolved IPs against blacklist networks.
  • Improved tools/nmap.py to reject XML inputs containing DTDs/entities and inputs larger than 10 MiB before parsing to mitigate entity expansion and memory exhaustion.
  • Constrained direct dependency upper bounds in pyproject.toml to avoid inadvertent major-version upgrades in release builds.
  • Added and updated tests: new tests/test_redaction.py, additional assertions in tests/test_memory.py, new nmap safety tests in tests/test_nmap_tool.py, added behavior test in tests/test_base_tool.py, and extended blacklist cases in tests/test_scope_validator.py.

Testing

  • Ran the automated test suite with pytest including tests/test_memory.py, tests/test_redaction.py, tests/test_nmap_tool.py, tests/test_base_tool.py, and tests/test_scope_validator.py, and all tests passed.
  • Confirmed new unit tests validate redaction, file permission semantics (private state files/dirs), nmap XML rejection heuristics, sanitized command exposure, and blacklist behavior.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant