Add AlertSuppression.ql for Rust (inline // codeql[...] suppression)
还没有人认领这个 Issue。
评估
调研方向
从 python/ql/src/AlertSuppression.ql 中提议的模式开始,然后阅读 shared/util/codeql/util/suppression/AlertSuppression.qll 以及 Rust Comment.qll 和 AstNode.qll 文件。添加 rust/ql/src/AlertSuppression.ql,并确认 // codeql[...] 和 // lgtm[...] 注释能够生成 Rust 警报抑制,而不更改 rust/ql/src/qlpack.yml。
由索引模型根据 Issue 内容生成。
描述
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:
- Shared suppression module:
shared/util/codeql/util/suppression/AlertSuppression.qll— requiresAstNode(withhasLocationInfo) andSingleLineComment(withhasLocationInfo,getText,toString) - Rust
Commentclass:rust/ql/lib/codeql/rust/elements/Comment.qll— already hasgetText()(raw text including//),getCommentText()(stripped),hasLocationInfo(inherited fromAstNode/Token), andtoString - Rust
AstNode:rust/ql/lib/codeql/rust/elements/AstNode.qll
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.
- 主要语言
- CodeQL
- 星标
- 10.1k
- 派生
- 2.1k
- 平均合并
- 2 天 11 小时
- 30 天内合并 PR
- 129
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
github/codeql 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
-
难度 2/5 1-3 小时 新手友好度 82/100
-
false-positive
难度 2/5 1-3 小时 新手友好度 70/100
-
False positive 未关闭false-positive
难度 4/5 3-5 天 新手友好度 15/100
-
false-positive
难度 3/5 1-2 天 新手友好度 68/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
phoenixframework/phoenix#6847 ·
-
intake mcp-intake needs-ac needs-human-review priority:medium type:bug
难度 2/5 1-3 小时 新手友好度 84/100
Ikalus1988/MisakaNet#2019 · 2 条评论 ·
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
avniproject/avni-client#2135 ·
-
agent/security hive/hosted-available-lke648397-260827-5n31 security
难度 2/5 1-3 小时 新手友好度 84/100
-
难度 2/5 1-3 小时 新手友好度 82/100
api7/lua-resty-saml#63 ·