Harden scan/repair pipelines with chain-aware validation, traversal defenses, and security-focused test coverage#17
Conversation
🔍 PR Security AuditScan Time: 2026-06-06T16:36:10.468Z ✅ No security issues detected 📁 Changed Files
View Run | SmartContractAudit PR Audit |
SolanaRemix
left a comment
There was a problem hiding this comment.
@copilot Thanks for your hard work on this PR! 🙏 I really like the focus on eliminating gaps in chain/address validation, path-handling, and security coverage. This aligns well with moving our scanning/repair pipelines toward production-grade security expectations.
✅ Address Validation and Chain Support
· Great to see chain-agnostic validation led by config/chains.json, including explicit support for Avalanche C-Chain, Arbitrum One, and Optimism.
· Enforcing strict failure paths for malformed addresses and unsupported chain inputs is a welcome improvement.
✅ Path Traversal Hardening
· The rework of file‑path validation to canonical checks (normalize + resolve + realpath) with strict base‑path allowlisting is a strong defense against ../ and symlink‑based escapes.
· Blocking traversal tricks in CLI file inputs effectively closes a common vector.
✅ CLI and Operational Robustness
· Hardened argument parsing and error handling in script/scan.js and script/repair.js will reduce surprising CLI failures.
· Adding structured JSON logging with severity levels and graceful shutdown (SIGTERM/SIGINT) makes the pipeline more observable and reliable.
· The --verify self‑check mode for scanner integrity is a nice feature for automated health checks.
✅ Security Utilities
· The reusable set of utilities (fixed‑window rate limiting, conversation history capping, exponential backoff with jitter, chain/address validation, secure path handling, structured logging) promotes consistency and reuse across the codebase.
✅ Documentation and Threat Modeling
· The updated README that explains supported chains, chain extension guidance, rate‑limit/environment configuration, and core security assumptions is clear and useful for both users and future maintainers.
· The PR’s own description of closing gaps after the removal of backdoors is transparent and builds trust.
Overall, this is a solid, well‑structured security upgrade. 👍
Before merging, please double‑check:
· Are there any remaining hard‑coded paths or un‑validated file inputs outside of the CLI that might still be vulnerable to path traversal?
· Did you test the new chain validation logic with both valid and invalid addresses for each newly added chain? (EVM checksum support looks correct, but a quick manual test on each chain is always good.)
· Are the new security utilities fully covered by unit tests, especially edge cases for rate limiting, backoff, and conversation capping?
· The PR is still in Draft mode – when you are ready, please convert it to “Ready for review” and notify the team for final approval and merge.
Looking forward to seeing this merged. 🚀
Feel free to adjust the tone or add any specific technical points you'd like to highlight.
There was a problem hiding this comment.
Pull request overview
This PR strengthens the CLI scan/repair surface by adding chain-aware address validation, safer path handling utilities, structured JSON logging, and a new Node.js test suite to regression-test key security behaviors.
Changes:
- Added reusable security utilities (chain/address validation, canonical path allowlisting, JSON logger, retry/backoff, fixed-window rate limiting, history capping).
- Hardened
script/scan.jsandscript/repair.jsto use the new validation/path defenses and emit structured logs. - Introduced a security-focused Node test suite and updated
package.json/CI install behavior accordingly.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
test/retryAndHistory.test.js |
Tests for conversation history capping and retry/backoff behavior. |
test/rateLimit.test.js |
Tests fixed-window rate limiting and proxy keying behavior. |
test/pathSecurity.test.js |
Tests canonical path allowlisting and traversal/symlink escape defenses. |
test/integration.test.js |
High-level scan→repair flow and key security regression checks. |
test/chainValidation.test.js |
Tests new chain metadata support and address validation failures. |
script/utils/retry.js |
Adds exponential backoff with jitter utility. |
script/utils/rateLimit.js |
Adds fixed-window in-memory rate limiter + request key helper. |
script/utils/pathSecurity.js |
Adds canonical path allowlisting (normalize/resolve/realpath). |
script/utils/logger.js |
Adds structured JSON logger with severity routing. |
script/utils/conversationHistoryCap.js |
Adds utility to cap conversation history length. |
script/utils/chainValidation.js |
Adds chain-driven address validation using config/chains.json. |
script/scan.js |
Updates scanner CLI to use chain/path validation, JSON logging, shutdown handling, and --verify. |
script/repair.js |
Updates repair CLI to use path validation and structured logging. |
README.md |
Documents --verify, supported chains, and threat-model assumptions. |
package.json |
Adds Node test runner, pins deps, and updates audit script/dependency versions. |
.github/workflows/pr-audit.yml |
Makes dependency install resilient when no npm lockfile exists. |
.eslintrc.cjs |
Adds minimal ESLint configuration for Node/ES2022. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| async function scanAddress(auditor, address, chain, modules) { | ||
| try { | ||
| const result = await auditor._deepScanner.scan(address, chain, modules); | ||
| logger.info('Address scanned', { |
| if (!targetPath || typeof targetPath !== 'string') { | ||
| throw new Error('Path must be a non-empty string'); | ||
| } | ||
|
|
||
| const normalizedBase = path.resolve(path.normalize(allowedBase)); | ||
| const normalizedTarget = path.resolve(path.normalize(targetPath)); |
| function createJitter(baseDelayMs, jitterRatio, randomFn) { | ||
| const spread = baseDelayMs * jitterRatio; | ||
| return baseDelayMs + Math.floor(randomFn() * spread); | ||
| } |
| return options; | ||
| } |
| const safeFile = ensureAllowedPath(options.file, process.cwd()); | ||
| const addresses = fs | ||
| .readFileSync(safeFile, 'utf8') | ||
| .split('\n') | ||
| .map((line) => line.trim()) | ||
| .filter((line) => line && !line.startsWith('#')); |
| const report = JSON.parse(fs.readFileSync(safeReportPath, 'utf8')); | ||
| const sourceCode = safeSourcePath ? fs.readFileSync(safeSourcePath, 'utf8') : ''; | ||
| const config = loadRepairConfig(); |
| 1. Add the chain metadata in `config/chains.json`. | ||
| 2. Provide `chainId`, `type` (`evm` or `solana`), and RPC endpoints. | ||
| 3. For EVM chains, addresses are validated with EIP-55 checksum support. | ||
| 4. Re-run `node script/scan.js --verify` to confirm validation coverage. |
| "dependencies": { | ||
| "ethers": "^5.7.2" | ||
| "ethers": "6.16.0" | ||
| }, |
| "repair": "node script/repair.js", | ||
| "audit": "node script/scan.js --modules antivirus,spam,honeypot", | ||
| "audit:deps": "pnpm audit --audit-level=high", | ||
| "audit:deps": "npm audit --audit-level=low", | ||
| "lint": "eslint .", |
PR #16 removed major backdoors but still had gaps in chain/address validation, path-handling hardening, and explicit security regression coverage. This update closes those gaps and aligns scan/repair behavior with production-grade security expectations for automated auditing workflows.
Address validation and chain support
config/chains.json.Path traversal hardening in scan/repair flows
normalize+resolve+realpath) with strict base-path allowlisting.../escapes, normalized traversal tricks, and symlink-based escape attempts in CLI file inputs.CLI security hardening and operational robustness
script/scan.jsandscript/repair.js.--verifyself-check mode for scanner integrity checks.Security utilities and deterministic behavior
Documentation and threat-model alignment