Skip to content

Security hardening: credential storage, input validation, and access controls - #515

Closed
nobugpal wants to merge 1 commit into
Panniantong:mainfrom
nobugpal:fix/security-hardening
Closed

Security hardening: credential storage, input validation, and access controls#515
nobugpal wants to merge 1 commit into
Panniantong:mainfrom
nobugpal:fix/security-hardening

Conversation

@nobugpal

Copy link
Copy Markdown

Summary

This PR addresses several hardening opportunities identified during a code audit of Agent-Reach. The changes improve credential protection, restrict configuration access, and add input validation boundaries — all without breaking backward compatibility.

Changes

Credential Storage (config.py)

  • Sensitive config values (API keys, auth tokens, cookies) are now encrypted at rest using a machine-local derived key with HMAC integrity verification
  • Unencrypted legacy configs remain fully readable — transparent upgrade path
  • Decryption happens automatically on Config.get() — no API changes for callers

Environment Variable Access (config.py)

  • Config.get() now only falls back to an explicit allowlist of known env var names, preventing unintended leakage of arbitrary environment variables

URL Validation (channels/web.py)

  • Added _validate_url() to block requests to private IPs, loopback addresses, cloud metadata endpoints, and internal hostnames before proxying to Jina Reader

Input Validation (transcribe.py)

  • Local file paths passed to transcribe() must now have a recognized audio extension (.wav, .mp3, .m4a, etc.) — non-audio files are rejected before processing
  • Added argument separator guard ("--") before user-supplied URL in the yt-dlp subprocess call

Privacy (cookie_extract.py)

  • Added docstring noting the scope of cookie extraction for transparency

Backward Compatibility

  • ✅ Existing unencrypted config files continue to work
  • ✅ Tests pass without modification (test env var names updated to use allowlisted keys)
  • ✅ All channel check behavior unchanged

…, and access controls

- Encrypt sensitive config values (API keys, tokens, cookies) at rest
  using a machine-local derived key with integrity verification
- Restrict Config.get() environment variable fallback to an explicit
  allowlist, preventing unintended leakage of unrelated env vars
- Add URL validation (SSRF protection) to WebChannel.read() before
  proxying requests to the Jina Reader service
- Add file extension validation for local audio file paths in
  transcribe() – only recognized audio formats are accepted
- Add argument separator guard ('--') before user-supplied URL in
  yt-dlp subprocess call for defense-in-depth
- Document cookie extraction scope in privacy notice

Backward compatible: existing unencrypted configs continue to work;
encrypted fields are transparently decrypted on read.
All existing tests pass.
@Panniantong

Copy link
Copy Markdown
Owner

感谢系统化做安全加固。merged #530#575#576#577 已以更小范围完成凭据脱敏、私有原子写入、URL 边界和显式授权;不采用自制机器派生加密,因此关闭此旧实现。

@Panniantong Panniantong closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants