Skip to content

Commit 3eb7150

Browse files
committed
fix(scan): check user include patterns before the extension allowlist
The scan path evaluated the built-in extension allowlist before user include globs, so an explicit include (e.g. **/*.ftl) could never force a non-allowlisted extension into a scan — while the preview/diff path already checks user includes first. The two paths disagreed about which files the same include selects. Reorders whyExcluded in scan/agent.go to match preview.go exactly: binary, user-exclude, user-include, extension allowlist, default excluded paths. User excludes still take precedence over includes, and binary/size guards still run regardless. Adds a regression test: a .ftl file with a matching include glob now yields ExcludeNone (fails on the previous ordering). Related to alibaba#371
1 parent 2bf81bc commit 3eb7150

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

internal/scan/agent.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,16 @@ func (a *Agent) whyExcluded(it model.ScanItem) model.ExcludeReason {
349349
if a.args.FileFilter != nil && a.args.FileFilter.IsUserExcluded(path) {
350350
return model.ExcludeUserRule
351351
}
352+
// User-include is checked before the extension allowlist (matching the
353+
// preview/diff path in internal/agent) so an explicit include glob can
354+
// admit otherwise-unsupported extensions (e.g. .ftl). See #371.
355+
if a.args.FileFilter != nil && a.args.FileFilter.HasInclude() && a.args.FileFilter.IsUserIncluded(path) {
356+
return model.ExcludeNone
357+
}
352358
ext := extFromPath(path)
353359
if ext != "" && !allowedext.IsAllowedExt(ext) {
354360
return model.ExcludeExtension
355361
}
356-
if a.args.FileFilter != nil && a.args.FileFilter.HasInclude() && a.args.FileFilter.IsUserIncluded(path) {
357-
return model.ExcludeNone
358-
}
359362
if allowedext.IsExcludedPath(path) {
360363
return model.ExcludeDefaultPath
361364
}

internal/scan/coverage_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ func TestWhyExcluded_AllBranches(t *testing.T) {
155155
filter: &rules.FileFilter{Include: []string{"src/**"}},
156156
want: model.ExcludeNone,
157157
},
158+
{
159+
// #371: a user-include glob must override the built-in extension
160+
// allowlist (as it already does on the preview/diff path). A
161+
// non-allowlisted extension (.ftl) with a matching include glob
162+
// must be included, not rejected as ExcludeExtension.
163+
name: "user include overrides extension allowlist",
164+
item: model.ScanItem{Path: "templates/email.ftl", Content: "x"},
165+
filter: &rules.FileFilter{Include: []string{"**/*.ftl"}},
166+
want: model.ExcludeNone,
167+
},
158168
{
159169
name: "default excluded path",
160170
item: model.ScanItem{Path: "pkg/handler_test.go", Content: "x"},

0 commit comments

Comments
 (0)