Prevent jscpd and secretlint report-folder race - #8633
Conversation
115b673 to
41dbebc
Compare
41dbebc to
d23b785
Compare
d23b785 to
62f1187
Compare
|
@trevor-vaughan I am currently building a generic way of dynamically inject cli args / ignore files to all linters called in project cli_lint_mode I think it will solve your use case (and many others), please tell me if you have any remarks :) |
62f1187 to
7e57015
Compare
|
Thanks @nvuillam I rebased and took a look at the changes afterwards with the help of our 馃 friends. Still working on getting a fully clean run with the new linters.
It looks like we still have issues around the root cause of this issue. If I'm reading things correctly:
This means that the delete happens while other linters are still walking the workspace. Any linter running in project mode without excluded-directories forwarding still scans the report folder (35 on
Also, the report folder exclusion disappears entirely as soon as a user sets This PR has 馃 discovered -> in #8646, the secretlint path writes The PR also carries fixes unrelated to exclusions that were found along the way while fixing tests:
I can split the fixes out into another PR if you like, but they ended up being related to fully evaluating this PR for |
|
Thanks for your efforts 馃槉 |
|
Yeah, if |
7e57015 to
fab5ead
Compare
TextReporter runs per linter the moment it finishes, so JsCpdLinter's
rmtree of megalinter-reports/copy-paste fired while secretlint was still
scanning the workspace in project mode. secretlint had already globbed
the jscpd report into its target set, crashed with ENOENT reading it, and
its stack trace was then parsed as SARIF and counted as a finding.
jscpd now writes its report to a temp folder outside the workspace and
copies it in only when clones are found, so MegaLinter never deletes files
other linters are scanning. secretlint gets a generated ignore file in the
report folder that merges the user's patterns with an exclusion for that
folder alone; narrowing a secrets scanner further would hide credentials
baked into build artifacts.
- fix: report a linter with unparsable SARIF as a warning, not a success
- A linter exiting 0 while emitting a stack trace instead of SARIF was
counted as zero findings and shown green; affects linters declaring
can_output_sarif (REPOSITORY_SECRETLINT, REPOSITORY_SEMGREP,
REPOSITORY_TRIVY). A linter that dies before producing SARIF now fails
with its raw output instead of a phantom finding.
- fix(secretlint): honor ignore patterns when REPORT_OUTPUT_FOLDER is off
- The generated ignore file was only written when reports could be
written; otherwise it fell back to passing a base name, so a
.secretlintignore under LINTER_RULES_PATH silently applied nothing. It
now goes to a temp folder outside the workspace, and the
--secretlintignore=<value> argument form is parsed too.
- fix(secretlint): stop falling back to .gitignore for a missing ignore file
- A typo in --secretlintignore used to promote .gitignore patterns to
authoritative status, excluding the very files a secrets scanner exists
to inspect. It now degrades with a warning and applies no fallback.
- fix(config): always exclude REPORT_OUTPUT_FOLDER from linted directories
- An EXCLUDED_DIRECTORIES override could drop it, making MegaLinter lint
its own output while reporters were still writing to it.
- test: cover jscpd report wiring and isolate ambient env in unit tests
- docs: document the secretlint ignore model and report-folder exclusion
Fixes: oxsecurity#3979
Assisted-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Trevor Vaughan <peiriannydd@gmail.com>
fab5ead to
3ba7906
Compare
|
@trevor-vaughan i made this attempt #8720 that seems simpler, please can you have a look and tell me what you think ? |
Summary
When
COPYPASTE_JSCPDandREPOSITORY_SECRETLINTran in parallel, jscpd's per-linter cleanup deletedmegalinter-reports/copy-pastewhile secretlint was still scanning the workspace, producing sporadicENOENTcrashes whose stack traces were then parsed as SARIF findings. This fixes the race by keeping jscpd's report out of the shared workspace until clones are found and by giving secretlint a generated ignore file that excludes only MegaLinter's own report folder. It also hardens SARIF result counting and the secretlint ignore-file handling so a crashed or misconfigured secrets scanner can no longer be reported as clean.Assisted-By: Claude Opus 5 (1M context) noreply@anthropic.com
Closes: #3979
Changes
copy-paste/only when clones are found, so no file another linter is scanning is ever deleted mid-run; a stale report from a previous run is cleared at construction time.copy-paste/folder is chmod'd to 0755 so a later non-root artifact-upload step can read it, instead of inheriting mkdtemp's 0700..secretlintignore-megalinterfile (in the report folder, or a temp folder when reports are disabled), honoring a file named inLINTER_RULES_PATHand parsing the--secretlintignore=<value>form.--secretlintignorefile no longer silently falls back to.secretlintignoreor.gitignore, which would exclude the exact files a secrets scanner must inspect; it degrades with a warning.can_output_sariflinters includingREPOSITORY_SECRETLINT,REPOSITORY_SEMGREP, andREPOSITORY_TRIVY.REPORT_OUTPUT_FOLDERis always excluded from linted directories, even whenEXCLUDED_DIRECTORIESis overridden.