Repository navigation
Warn when App Security scans another app's files - #8763
Conversation
Secret scanning kept any app configuration file named like the selected one, so a nested app's shopify.app.toml was scanned while its shopify.app.staging.toml wasn't. Compare the path relative to the app directory instead, so only the selected file is scanned. Gathering no longer skips a directory that holds another app configuration file, so its files are scanned as this app's. Warn about each such directory and suggest the --exclude that leaves it out.
472e640 to
51e76cc
Compare
The directory name comes from the repository, so a name such as $(touch PWNED) ran when the user pasted the suggestion into a shell. Quote it the way the generated commands are quoted, for the user's shell.
--exclude globs are matched from the real working directory, but the warnings used the working directory as given. When that path went through a symbolic link, the suggested --exclude didn't match the directory it named.
--exclude takes globs, so a directory name with glob syntax didn't match itself, and a leading ! negated the pattern and excluded everything else. Escape the name so the suggestion matches only that directory.
Cover a directory name that is shell and glob syntax, a working directory reached through a symbolic link, the warning with --list-files, and an --exclude built from the suggestion removing only that directory. Pin that a directory whose app configuration file Git ignores isn't reported.
gonzaloriestra
left a comment
There was a problem hiding this comment.
I added one comment, but not-blocking
| // The directory name comes from the repository, so it's quoted before the user can paste it into a shell. | ||
| body: [ | ||
| 'Use', | ||
| {command: `--exclude ${quoteShellArgument(literalGlobPattern(path), shellForPlatform())}`}, |
There was a problem hiding this comment.
With --include-dir ../backend, the warning suggests --exclude '../backend'. But the walker checks exclusions against entries inside each scan directory, so this pattern never excludes the included root. Its files remain scanned and the warning persists.
There was a problem hiding this comment.
Good catch. The walker never tested a scan directory itself, or the directories above it, against --exclude, so --exclude ../shared didn't remove --include-dir ../shared/sdk either. Fixed in 53a0db3: the suggested --exclude '../backend' now removes ../backend, and the warning goes away. While there, 9a5ef30 resolves each pattern's literal start against the working directory, so ./src, src/ and ../app/src (from inside app) now work too.
The walker only tested the entries inside a scan directory, so an --exclude that matched an --include-dir, or a directory above it, removed nothing. Test the scan directory and its ancestors up to the working directory too, so adding a directory can't undo an exclusion, and skip the ignored-scan-directory warning for a directory that gathers nothing.
…tory Patterns were matched as typed against the shortest path relative to the working directory, so ./src, src/ and, from inside app, ../app/src excluded nothing, and neither did . or ../app. Resolve each pattern up to its first glob segment the same way paths are, and keep the rest as typed. Drop an empty pattern, which would otherwise match the working directory.
node:path's join wrote the pattern with backslashes on Windows, which --exclude reads as glob escapes, so the pattern was kept as typed.
WHY are these changes introduced?
Since #8738, file gathering no longer skips a directory that holds another
shopify.app*.toml, so a nested app's files are scanned as part of this app, and nothing tells the user. Secret scanning also compared app configuration files by name only. A nested app'sshopify.app.tomlwas scanned when the selected file had the same name, while itsshopify.app.staging.tomlwasn't.Adding a warning that suggests
--excludeexposed two gaps in--exclude:--include-dir ../backend --exclude ../backendstill scanned../backend, and--exclude ../shareddidn't remove--include-dir ../shared/sdk.app,./src,src/,../app/src,.and../appall excluded nothing.WHAT is this pull request doing?
--excludethat leaves it out. The suggestion is relative to the real working directory, escaped as a glob and quoted for the user's shell. The warning shows on a scan and with--list-files. Once you exclude the directory, the warning stops. A nested app whose configuration file is gitignored doesn't trigger it.--excludenow removes a whole scan directory when it, or any directory above it up to the working directory, matches. Adding a directory can't undo an exclusion. This includes the app directory when you run from above it, for example--exclude apps/webfrom the repository root. The selected app configuration file is still scanned. An excluded directory doesn't get the "ignored by Git" warning.--excludepattern, up to its first glob segment, against the working directory../srcandsrc/meansrc, and from insideapp, so does../app/src..means the working directory itself. The rest of the pattern is kept as typed, so**/generatedand../backend/**behave as before. An empty pattern is ignored.findExtensionsdocstring: extensions in a nested app or an--include-dirdirectory count as this app's.How to manually test your changes?
The output warns about
../backendandapps/child, and suggests--exclude '../backend'and--exclude 'apps/child'. Rerun with--exclude ../backend --exclude apps/child --exclude ./src: the warnings go away, and onlyshopify.app.tomland the.shopify/files are listed.Checklist
patchfor bug fixes ·minorfor new features ·majorfor breaking changes) and added a changeset withpnpm changeset add