-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(config): template exclusion logic for paths with reserved names #6663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(config): template exclusion logic for paths with reserved names #6663
Conversation
Prev, the template exclusion logic checked if the full file path contained any of the known miscellaneous directory names (e.g., helpers, .git). This caused false positives when valid templates were stored in paths where a parent directory matched one of these names (e.g., /path/to/somewhere/that/has/helpers/dir/name/). This commit introduces `IsTemplateWithRoot`, which checks for excluded directories relative to a provided root directory. It splits the relative path into components. Signed-off-by: Dwi Siswanto <git@dw1.io>
WalkthroughAdds a root-aware template detection function Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used📓 Path-based instructions (1)**/*.go📄 CodeRabbit inference engine (CLAUDE.md)
Files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (3)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
pkg/catalog/config/template.go (1)
75-114: Core logic is sound; consider edge case for robustness.The root-aware exclusion logic correctly addresses the bug:
- Computes relative paths when rootDir is provided and filters based on path components only for non-absolute paths
- Avoids false positives from parent directory names outside the root
Optional edge case refinement for Line 88:
The check
!strings.HasPrefix(rel, "..")could theoretically match directory names like"..sneaky"(though unlikely in practice for template directories). Consider a more precise check:- if err == nil && !strings.HasPrefix(rel, "..") { + if err == nil && rel != ".." && !strings.HasPrefix(rel, ".."+string(os.PathSeparator)) {This ensures only paths genuinely outside the root (e.g.,
"../"or"../foo") are caught, not directories with names starting with"..".
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
pkg/catalog/config/nucleiconfig.go(1 hunks)pkg/catalog/config/template.go(3 hunks)pkg/catalog/config/template_test.go(1 hunks)pkg/catalog/disk/find.go(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.go: Format Go code usinggo fmt ./...
Run static analysis usinggo vet ./...on Go code
Files:
pkg/catalog/disk/find.gopkg/catalog/config/nucleiconfig.gopkg/catalog/config/template.gopkg/catalog/config/template_test.go
pkg/catalog/**/*.go
📄 CodeRabbit inference engine (CLAUDE.md)
Template discovery and loading from disk/remote sources should be implemented in pkg/catalog
Files:
pkg/catalog/disk/find.gopkg/catalog/config/nucleiconfig.gopkg/catalog/config/template.gopkg/catalog/config/template_test.go
🧬 Code graph analysis (2)
pkg/catalog/disk/find.go (1)
pkg/catalog/config/template.go (1)
IsTemplateWithRoot(75-114)
pkg/catalog/config/nucleiconfig.go (1)
pkg/catalog/config/template.go (1)
IsTemplateWithRoot(75-114)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Lint
🔇 Additional comments (6)
pkg/catalog/disk/find.go (2)
214-214: LGTM!The change correctly passes
absPathas the root directory to enable root-aware template detection, ensuring that excluded directories are checked relative to the traversal root rather than the full absolute path.
238-238: LGTM!Consistent with the native filesystem branch, this correctly applies root-aware template detection for the embedded filesystem case.
pkg/catalog/config/template_test.go (1)
9-78: Excellent test coverage for the bug fix.The test suite effectively validates the root-aware exclusion logic:
- Lines 35-39 test the bug fix scenario where an excluded directory name appears in a parent path
- Lines 41-45 confirm that excluded directories within the root are still properly filtered
- Lines 47-51 verify backward compatibility when no root is provided
The table-driven approach with clear test case names makes the test suite maintainable and comprehensive.
pkg/catalog/config/template.go (2)
68-70: Good backward compatibility design.Delegating to
IsTemplateWithRoot(fpath, "")maintains the existingIsTemplateAPI while enabling the new root-aware behavior. When no root is provided, the function falls back to checking path components only for relative paths, skipping the check for absolute paths.
177-177: LGTM!Correctly applies root-aware template detection when building the template index, ensuring excluded directories are evaluated relative to the templates directory rather than the full absolute path.
pkg/catalog/config/nucleiconfig.go (1)
203-207: Go version supportsstrings.FieldsSequsage.The project requires Go 1.24.2 (per
go.mod), which exceeds the Go 1.23 minimum needed forstrings.FieldsSeq. The change fromstrings.Fieldstostrings.FieldsSeqis compatible and provides allocation efficiency. The paired update toIsTemplateWithRootcorrectly applies the templates directory as the root parameter.
Signed-off-by: Dwi Siswanto <git@dw1.io>
Proposed changes
Prev, the template exclusion logic checked if the
full file path contained any of the known
miscellaneous directory names (e.g., "helpers",
".git"). This caused false positives when valid
templates were stored in paths where a parent
directory matched one of these names (e.g.,
"/path/to/somewhere/that/has/helpers/dir/name/").
This commit introduces
IsTemplateWithRoot, whichchecks for excluded directories relative to a
provided root directory. It splits the relative
path into components.
Fixes #6662.
Checklist
Summary by CodeRabbit
Tests
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.