Skip to content

fix(catalog): preserve template names with config substrings - #7598

Open
james-yusuke wants to merge 6 commits into
projectdiscovery:devfrom
james-yusuke:test/fix-config-name-template-filter
Open

fix(catalog): preserve template names with config substrings#7598
james-yusuke wants to merge 6 commits into
projectdiscovery:devfrom
james-yusuke:test/fix-config-name-template-filter

Conversation

@james-yusuke

@james-yusuke james-yusuke commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix template discovery when a valid template filename contains a known configuration filename, such as cves.json.yaml.

Root cause

The catalog and shared template predicate used substring matching to skip known configuration files. This also excluded valid YAML or JSON templates whose names merely contained cves.json, contributors.json, or TEMPLATES-STATS.json.

Changes

  • Match known configuration filenames exactly, using the basename.
  • Add regression coverage for direct template paths and directory traversal.

Validation

  • /usr/local/go/bin/go test ./pkg/catalog/... -count=1
  • /usr/local/go/bin/go vet ./pkg/catalog/...

Summary by CodeRabbit

  • Bug Fixes

    • Template discovery now correctly accepts filenames that contain known configuration filenames, such as cves.json.yaml.
    • Known configuration files are identified by their complete filenames, preventing valid templates from being incorrectly excluded.
  • Tests

    • Added coverage for template names containing configuration filename text.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 12088802-42c2-4d79-98fa-1cf220e16957

📥 Commits

Reviewing files that changed from the base of the PR and between 0c12666 and ddd5b69.

📒 Files selected for processing (2)
  • pkg/catalog/disk/find.go
  • pkg/catalog/disk/known-files.go
💤 Files with no reviewable changes (1)
  • pkg/catalog/disk/known-files.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/catalog/disk/find.go

Walkthrough

Known config-file detection now compares exact filenames or path basenames rather than substrings. Template classification and discovery tests cover filenames containing known config names.

Changes

Template filename detection

Layer / File(s) Summary
Exact config matching
pkg/catalog/config/template.go, pkg/catalog/disk/find.go
Known config checks use exact membership or basename matching during template classification and discovery.
Filename matching coverage
pkg/catalog/config/template_test.go, pkg/catalog/disk/find_test.go
Tests verify that http/cves.json.yaml is accepted as a template for direct classification and catalog discovery.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

I’m a bunny with a template to parse,
No substring trap shall block it afar.
Exact names hop into the known-file row,
While cves.json.yaml gets room to grow.
Tests nibble happily, all green in the burrow.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix: preserving valid template names that contain config substrings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@james-yusuke
james-yusuke marked this pull request as ready for review July 26, 2026 00:16
@Mzack9999 Mzack9999 added the Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors. label Jul 26, 2026
@Mzack9999

Copy link
Copy Markdown
Member

@coderabbitai create an issue to track this PR (do not assign it to me)

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

repo="projectdiscovery/nuclei"
pr_number="7598"
pr_url="https://github.com/${repo}/pull/${pr_number}"

comment_url="$(
  gh api "repos/${repo}/issues/${pr_number}/comments" --paginate \
    --jq '.[] | select(.user.login == "Mzack9999" and (.body | contains("`@coderabbitai` create an issue to track this PR"))) | .html_url' \
    | tail -n 1
)"

if [[ -z "$comment_url" ]]; then
  echo "Could not find the requesting comment URL on ${pr_url}." >&2
  exit 1
fi

body="$(cat <<EOF
## Summary
Track the template-discovery behavior corrected in pull request #${pr_number}: valid template filenames that contain a known configuration filename, such as \`cves.json.yaml\`, must not be excluded.

## Required changes
Ensure both catalog-level template detection and disk catalog traversal identify known configuration files by an exact basename match rather than substring matching.

## Rationale
Substring matching incorrectly filters valid templates whose names merely include a known configuration-file name.

## Affected areas
- \`pkg/catalog/config/template.go\`
- \`pkg/catalog/disk/find.go\`
- Regression tests covering direct template paths and directory traversal

## Acceptance criteria
- A template such as \`http/cves.json.yaml\` is discovered when supplied directly.
- The same template is discovered during directory traversal.
- Actual known configuration files continue to be excluded.
- Relevant catalog tests and \`go vet\` pass.

## Backlinks
- Pull request: ${pr_url}
- Request: ${comment_url}
- Requested by: `@Mzack9999`
EOF
)"

issue_url="$(gh issue create \
  --repo "$repo" \
  --title "Track exact-basename matching for known template configuration files" \
  --body "$body")"

echo "Created issue: ${issue_url}"

Length of output: 1968


@Mzack9999 Created unassigned tracking issue #7610 for this PR: #7610

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Track exact-basename matching for known template configuration files

2 participants