Skip to content

fix(parser): kics-scan ignore-line/ignore-block misapplied in YAML files with resolved references - #8080

Open
theo-sardin wants to merge 2 commits into
Checkmarx:masterfrom
HelloWatt:fix/ignore-comments-with-include-resolved-files
Open

fix(parser): kics-scan ignore-line/ignore-block misapplied in YAML files with resolved references#8080
theo-sardin wants to merge 2 commits into
Checkmarx:masterfrom
HelloWatt:fix/ignore-comments-with-include-resolved-files

Conversation

@theo-sardin

Copy link
Copy Markdown

Closes #8078

Reason for for this change

  • kics-scan ignore-line / ignore-block comments are broken in YAML files that resolve other files (e.g. docker-compose include:): ignore positions are collected while parsing the resolved (combined) content, so they are shifted by the inlined lines, while results are reported on the original file lines. The ignore then does nothing or can even shift the ignores to a wrong line.

Proposed change

  • In the sink, when a file has resolved references, replace documents.IgnoreLines with lines recomputed from the original file content via the existing model.GetIgnoreLines helper, before building the FileMetadata. This mirrors what the Helm sink already does (getOriginalIgnoreLines) and what the secrets inspector already did (which it doesn't need to do anymore since it's caught upstream).
  • Remove the now-redundant model.GetIgnoreLines call in the secrets inspector: FileMetadata.LinesIgnore now carries correct file coordinates when it reaches the engines. This also avoids re-parsing the same file once per secrets query.
  • Add a regression test (TestKics_sinkIgnoreLinesWithResolvedFiles) with fixtures under test/fixtures/resolve_ignore_lines/: a compose file with an include (ignore lines must stay [6, 7], previously [12, 13]) and one without (unchanged path).

Files without resolved references are untouched.

I submit this contribution under the Apache-2.0 license.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(parser): kics-scan ignore-line/ignore-block misapplied in YAML files with resolved references

1 participant