Skip to content

Commit 49ff967

Browse files
committed
Rust: Add a dataflow sources test for the Axum web fraemework.
1 parent e56519d commit 49ff967

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

rust/ql/test/library-tests/dataflow/sources/options.yml

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ qltest_dependencies:
1010
- poem = { version = "3.1.10" }
1111
- serde = { version = "1.0.219" }
1212
- actix-web = { version = "4.10.2" }
13+
- axum = { version = "0.8.4" }
14+
- serde_json = { version = "1.0.140" }

rust/ql/test/library-tests/dataflow/sources/web_frameworks.rs

+71
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,74 @@ mod actix_test {
126126
// ...
127127
}
128128
}
129+
130+
mod axum_test {
131+
use axum::Router;
132+
use axum::routing::get;
133+
use axum::extract::{Path, Query, Request, Json};
134+
use std::collections::HashMap;
135+
use crate::web_frameworks::sink;
136+
137+
async fn my_axum_handler_1(Path(a): Path<String>) -> &'static str { // $ MISSING: Alert[rust/summary/taint-sources]
138+
sink(a.as_str()); // $ MISSING: hasTaintFlow
139+
sink(a.as_bytes()); // $ MISSING: hasTaintFlow
140+
sink(a); // $ MISSING: hasTaintFlow
141+
142+
""
143+
}
144+
145+
async fn my_axum_handler_2(Path((a, b)): Path<(String, String)>) -> &'static str { // $ MISSING: Alert[rust/summary/taint-sources]
146+
sink(a); // $ MISSING: hasTaintFlow
147+
sink(b); // $ MISSING: hasTaintFlow
148+
149+
""
150+
}
151+
152+
async fn my_axum_handler_3(Query(params): Query<HashMap<String, String>>) -> &'static str { // $ MISSING: Alert[rust/summary/taint-sources]
153+
for (key, value) in params {
154+
sink(key); // $ MISSING: hasTaintFlow
155+
sink(value); // $ MISSING: hasTaintFlow
156+
}
157+
158+
""
159+
}
160+
161+
async fn my_axum_handler_4(request: Request) -> &'static str { // $ MISSING: Alert[rust/summary/taint-sources]
162+
sink(request.body()); // $ MISSING: hasTaintFlow
163+
request.headers().get("header").unwrap(); // $ MISSING: hasTaintFlow
164+
sink(request.into_body()); // $ MISSING: hasTaintFlow
165+
166+
""
167+
}
168+
169+
async fn my_axum_handler_5(Json(payload): Json<serde_json::Value>) -> &'static str { // $ MISSING: Alert[rust/summary/taint-sources]
170+
sink(payload.as_str()); // $ MISSING: hasTaintFlow
171+
sink(payload); // $ MISSING: hasTaintFlow
172+
173+
""
174+
}
175+
176+
async fn my_axum_handler_6(body: String) -> &'static str { // $ MISSING: Alert[rust/summary/taint-sources]
177+
sink(body); // $ MISSING: hasTaintFlow
178+
179+
""
180+
}
181+
182+
async fn my_axum_handler_7(body: String) -> &'static str { // $ MISSING: Alert[rust/summary/taint-sources]
183+
sink(body); // $ MISSING: hasTaintFlow
184+
185+
""
186+
}
187+
188+
async fn test_axum() {
189+
let app = Router::<()>::new()
190+
.route("/foo/{a}", get(my_axum_handler_1))
191+
.route("/bar/{a}/{b}", get(my_axum_handler_2))
192+
.route("/1/:a", get(my_axum_handler_3))
193+
.route("/2/:a", get(my_axum_handler_4))
194+
.route("/3/:a", get(my_axum_handler_5))
195+
.route("/4/:a", get(my_axum_handler_6).get(my_axum_handler_7));
196+
197+
// ...
198+
}
199+
}

0 commit comments

Comments
 (0)