Skip to content

Fix the behavior of the GitLab AppSec SAST comment

Nick Malcolm requested to merge appsec-sast-comment-fix into master

What does this MR do and why?

Fix the behavior of the GitLab AppSec SAST comment. Resolves Fix SAST bot comments (gitlab-com/gl-security/product-security/appsec/sast-custom-rules#39 - closed).

Previously, the comment would have the warning followed immediately by the footer comment. This was due to an insufficient number of newlines, based on how GitLab Flavored Markdown works.

The comment would also fail to apply a quick action. This was due to it being prefixed by two spaces.

Example of bug

From !154910 (comment 1983774478)

Screenshot_2024-07-09_at_1.43.47_PM

Bug explanation

Newlines

A line break is inserted (a new paragraph starts) if the previous text is ended with two newlines, like when you press Enter twice in a row. If you only use one newline (press Enter once), the next sentence remains part of the same paragraph. Use this approach if you want to keep long lines from wrapping, and keep them editable:

  • Bug: SAST warning and the footer text run together in the same paragraph, due to insufficient newlines
  • Fix: go from one \n to two two \n\ns
Quick actions not applied

Heredoc syntax:

You may indent the ending identifier if you place a “-” after <<:

...

To have indented content as well as an indented closing identifier, you can use a “squiggly” heredoc, which uses a “~” instead of a “-” after <<:

https://ruby-doc.org/3.2.1/syntax/literals_rdoc.html#label-Here+Document+Literals

  • Bug: Quick action not applied due to it being prefixed with whitespace ( /label ...)
  • Fix: Use ~ syntax to remove indenting spaces

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Edited by Nick Malcolm

Merge request reports

Loading