Skip to content

Commit 4dbe357

Browse files
authored
controllers/github: Use axum extractors (#5874)
The `Bytes` extractor already has a request body limit built in, so we don't the extra `content_length()` check.
1 parent 5bc7298 commit 4dbe357

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/controllers/github/secret_scanning.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use crate::app::AppState;
22
use crate::controllers::frontend_prelude::*;
33
use crate::models::{ApiToken, User};
44
use crate::schema::api_tokens;
5-
use crate::util::read_fill;
65
use crate::util::token::SecureToken;
76
use anyhow::{anyhow, Context};
7+
use axum::body::Bytes;
8+
use axum::extract::State;
89
use base64;
910
use http::HeaderMap;
1011
use once_cell::sync::Lazy;
@@ -232,29 +233,22 @@ pub enum GitHubSecretAlertFeedbackLabel {
232233
}
233234

234235
/// Handles the `POST /api/github/secret-scanning/verify` route.
235-
pub async fn verify(mut req: ConduitRequest) -> AppResult<Json<Vec<GitHubSecretAlertFeedback>>> {
236+
pub async fn verify(
237+
state: State<AppState>,
238+
headers: HeaderMap,
239+
body: Bytes,
240+
) -> AppResult<Json<Vec<GitHubSecretAlertFeedback>>> {
236241
conduit_compat(move || {
237-
let max_size = 8192;
238-
let length = req.content_length();
239-
240-
if length > max_size {
241-
return Err(bad_request(&format!("max content length is: {max_size}")));
242-
}
243-
244-
let mut json = vec![0; length as usize];
245-
read_fill(req.body_mut(), &mut json)?;
246-
247-
let state = req.app();
248-
verify_github_signature(req.headers(), state, &json)
242+
verify_github_signature(&headers, &state, &body)
249243
.map_err(|e| bad_request(&format!("failed to verify request signature: {e:?}")))?;
250244

251-
let alerts: Vec<GitHubSecretAlert> = json::from_slice(&json)
245+
let alerts: Vec<GitHubSecretAlert> = json::from_slice(&body)
252246
.map_err(|e| bad_request(&format!("invalid secret alert request: {e:?}")))?;
253247

254248
let feedback = alerts
255249
.into_iter()
256250
.map(|alert| {
257-
let label = alert_revoke_token(state, &alert)?;
251+
let label = alert_revoke_token(&state, &alert)?;
258252
Ok(GitHubSecretAlertFeedback {
259253
token_raw: alert.token,
260254
token_type: alert.r#type,

0 commit comments

Comments
 (0)