mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
fix(api): use constant time comparison for tokens
This commit is contained in:
parent
2d40a1ee16
commit
9c1acd84e1
3 changed files with 8 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -95,6 +95,7 @@ dependencies = [
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
|
"subtle",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tower 0.4.13",
|
"tower 0.4.13",
|
||||||
"tower-http",
|
"tower-http",
|
||||||
|
|
|
||||||
|
|
@ -26,3 +26,4 @@ reverse-proxy-service = { version = "0.2.1", features = ["axum"] }
|
||||||
serde_urlencoded = "0.7.1"
|
serde_urlencoded = "0.7.1"
|
||||||
tower = "0.4.13"
|
tower = "0.4.13"
|
||||||
tower-http = { version = "0.5.2", features = ["catch-panic"] }
|
tower-http = { version = "0.5.2", features = ["catch-panic"] }
|
||||||
|
subtle = "2.6.1"
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ use axum::{
|
||||||
response::Response,
|
response::Response,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use subtle::ConstantTimeEq;
|
||||||
|
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
use crate::auth::AuthState;
|
use crate::auth::AuthState;
|
||||||
|
|
@ -48,9 +50,10 @@ pub async fn auth(State(ctx): State<ApiContext>, mut req: Request, next: Next) -
|
||||||
.expect("missing api config")
|
.expect("missing api config")
|
||||||
.temp_token2
|
.temp_token2
|
||||||
.as_ref()
|
.as_ref()
|
||||||
// this is NOT how you validate tokens
|
&& app_auth_header
|
||||||
// but this is low abuse risk so we're keeping it for now
|
.as_bytes()
|
||||||
&& app_auth_header == config_token2
|
.ct_eq(config_token2.as_bytes())
|
||||||
|
.into()
|
||||||
{
|
{
|
||||||
authed_app_id = Some(1);
|
authed_app_id = Some(1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue