fix(security): address critical vulnerabilities from code review#3
Merged
Conversation
Security fixes: - Add path traversal protection in collectGoFiles (CWE-22) - Add arbitrary file write protection in fixer (CWE-73) - Add symlink TOCTOU race condition prevention (CWE-61) - Add resource limits to prevent DoS (MaxFiles, MaxSize, MaxDepth) Code quality fixes: - Fix context leak false positives (only track known cancel functions) - Extract shared helpers to rules/helpers.go (isHTTPHandler, etc.) - Remove misleading AST modification code in fixer - Fix fixer build error (redundant newline in fmt.Println) Testing improvements: - Add 50 comprehensive tests for detection rules - Add security validation tests for fixer - Test coverage: fixer 28.2%, rules 14.8% Key tests added: - Context leak detection with false positive prevention - HTTP handler detection for multiple frameworks - Path traversal/symlink security validation - Identifier validation for safe extraction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses all critical security vulnerabilities and code quality issues identified in the comprehensive code review.
Security Fixes (Critical)
Path Traversal Protection (CWE-22)
validatePath()function inmain.goArbitrary File Write Protection (CWE-73)
validatePathForWrite()infixer/fixer.goResource Exhaustion Prevention (CWE-400)
Code Quality Fixes
Context Leak False Positives
Fixed detection to only track calls to known cancel functions from the
cancelFuncsmap, preventing false positives when other functions with matching names exist.Shared Helpers Extraction
Created
rules/helpers.gowith shared functions:isHTTPHandler()- expanded to support Echo, Gin, Chi, Fiber frameworksestimateStructSizes()getTypeName()itoa()isInLoop()findFunctionContaining()Fixer Cleanup
modified = truebut never applied changesisValidIdentifier()for safe message extractionTesting
New Tests Added
All 50 tests pass.
Test Plan
go build -o goperf .succeedsgo test ./...passes (50 tests)