github / github/codeql

Incorrect escaping of SARIF message.text

Open
#14,128 1 comment 0 reactions 1 assignee Claimed by @aeisenberg View on GitHub
question
Dominant language
CodeQL
Stars
10.1k
Forks
2.1k
Avg merge
2d 15h
Merged PRs (30d)
141

Description

**Description of the issue**

Hello, after uploading a SARIF log to GitHub and opening the results using Code Scanning, I found that the message content had been altered before display: backquotes were not displayed in the message, and underscores were escaped.

For example:

```
"message": {
"text": "Some issue with `backquoted expression`, and path `some.path_with.underscore_suffix` on line 100"
},
```

and the result displayed on GitHub is:
```
Some issue with backquoted expression, and path some.path\_with.underscore\_suffix on line 100
```

This seems to be a bug, I did not see any requirement about this kind of escaping in the [SARIF specification](https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html). As far as I understand the text should be rendered as is.
However in section "K.4 Comprehensive SARIF file" I see in the example:

```
"text": "Variable \"{0}\" was used without being initialized.

It was declared [here]({1}).",

"markdown": "Variable `{0}` was used without being initialized.

It was declared [here]({1})."
```
so it seems more correct to use `"\` instead of backquotes in the plain text string, and use backquotes in the markdown string. I have tried that, and the Code Scanning displayed results did not have any issue this time (they seem to use the markdown string), so the markdown version can be used as a workaround.

Although there was no special highlighting of the escaped \`string\`, contrary to what would be expected in Markdown rendering, so that could be improved.

Thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.