Skip to content

Security hardening, refactor and robustness fixes across AI providers, tools and CLI - #2

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

Security hardening, refactor and robustness fixes across AI providers, tools and CLI#2
prithvee07 wants to merge 1 commit into
mainfrom
codex/learn-the-codebase-hz53x0

Conversation

@prithvee07

Copy link
Copy Markdown
Owner

Motivation

  • Improve security and privacy at the boundary between external tools and AI/persistence by redacting secrets, enforcing file permissions and avoiding accidental leakage of sensitive command arguments.
  • Harden parsing and validation to prevent common injection and resource-exhaustion attacks (e.g. large or malicious XML, unsafe flags), and make provider/tool integrations more robust.
  • Clean up imports, fix minor CLI/formatting issues and tighten dependency bounds for more predictable builds.

Description

  • Add central redaction utilities via utils.redaction.redact_sensitive_text and apply redaction to tool outputs and session persistence, and ensure BaseTool never exposes raw executable command with secrets by logging a sanitized safe_command instead.
  • Secure session and report files by using restrictive file permissions (0o600 for files, 0o700 for directories) when saving state and reports, and use safe open flags to avoid symlink following.
  • Harden parsers and validators: tools/nmap.py now rejects DTD/entity-containing or oversized XML inputs; ScopeValidator tightens blacklist logic and DNS resolution checks to prevent DNS-rebinding and blocks non-global addresses; many tool parsers and wrappers were made more resilient against malformed output.
  • Refactor and tidy code style across the project: rearranged imports, consistent string quoting, trailing commas, re-ordered/cleaned ai.prompt_templates.__init__, provider implementations updated to import LangChain message classes consistently, and dependency bounds added to pyproject.toml.

Testing

  • Ran the unit test suite with pytest (updated/added tests include tests/test_redaction.py, enhancements to tests/test_memory.py, tests/test_nmap_tool.py, tests/test_base_tool.py, and others) and verified the test run completed successfully.
  • New tests exercise redaction, secure file permissions, nmap XML protections, and command sanitization and passed.
  • No failing automated tests remained after the changes.

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