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

Aperta Adatta ai principianti
#21,637 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
rust
Ambito
security

Direzione di ricerca

Inizia con il pattern proposto in python/ql/src/AlertSuppression.ql, poi leggi shared/util/codeql/util/suppression/AlertSuppression.qll e i file Rust Comment.qll e AstNode.qll. Aggiungi rust/ql/src/AlertSuppression.ql e conferma che i commenti // codeql[...] e // lgtm[...] producano soppressioni degli alert Rust senza modificare rust/ql/src/qlpack.yml.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
CodeQL
Stelle
10.1k
Fork
2.1k
Merge medio
2g 11h
PR unite (30g)
129

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di github/codeql

Tutte le issue di github/codeql

Issue simili

Altre issue su Security

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.