Add AlertSuppression.ql for Rust (inline // codeql[...] suppression)

Open Beginner friendly
#21,637 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Quiet
Tech stack
rust
Domain
security

Research direction

Start with the proposed pattern in python/ql/src/AlertSuppression.ql, then read shared/util/codeql/util/suppression/AlertSuppression.qll and the Rust Comment.qll and AstNode.qll files. Add rust/ql/src/AlertSuppression.ql and confirm that // codeql[...] and // lgtm[...] comments produce Rust alert suppressions without changing rust/ql/src/qlpack.yml.

Written by the indexing model from the issue text.

Description

Description of the issue

Rust is missing an AlertSuppression.ql query, which means // codeql[...] and // lgtm[...] inline suppression comments have no effect on Rust code scanning alerts. Every other supported language (C++, C#, Go, Java, JavaScript, Python, Ruby, Swift) has this query.

All the building blocks already exist in the Rust CodeQL library:

Proposed implementation

A new file at rust/ql/src/AlertSuppression.ql, following the same pattern as python/ql/src/AlertSuppression.ql:

/**
 * @name Alert suppression
 * @description Generates information about alert suppressions.
 * @kind alert-suppression
 * @id rust/alert-suppression
 */

private import codeql.util.suppression.AlertSuppression as AS
private import codeql.rust.elements.Comment as C
private import codeql.rust.elements.AstNode as A

class AstNode instanceof A::AstNode {
  predicate hasLocationInfo(
    string filepath, int startline, int startcolumn, int endline, int endcolumn
  ) {
    super.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
  }

  string toString() { result = super.toString() }
}

class SingleLineComment instanceof C::Comment {
  SingleLineComment() {
    // Only match single-line comments (// ...), not block comments (/* ... */)
    super.getText().matches("//%")
  }

  predicate hasLocationInfo(
    string filepath, int startline, int startcolumn, int endline, int endcolumn
  ) {
    super.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
  }

  string getText() { result = super.getText() }

  string toString() { result = super.toString() }
}

import AS::Make<AstNode, SingleLineComment>

The qlpack.yml at rust/ql/src/qlpack.yml already depends on codeql/util, so no dependency changes are needed.

Motivation

Without this, there is no way to suppress false positives inline for Rust. The only workaround is dismissing alerts via the GitHub API or UI, which doesn't persist reliably across code changes.

Dominant language
CodeQL
Stars
10.1k
Forks
2.1k
Avg merge
2d 11h
Merged PRs (30d)
129

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/codeql

All issues in github/codeql

Similar issues

More Security issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.