mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-05 04:26:30 +00:00
auth-api: check for new prefixed cookies as well
this makes sure that newly generated cookies that are prefixed with, for example, `__Host-`, for security purposes, are correctly picked up on. otherwise, the new cookies would not be able to yield proper authentication. currently this still falls back to insecure non-prefixed cookies. we should deprecate them in the long-term and remove this fallback. Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
This commit is contained in:
parent
b598e03287
commit
6f61b991a0
@ -203,18 +203,36 @@ fn extract_auth_data(
|
||||
auth_context: &dyn AuthContext,
|
||||
headers: &http::HeaderMap,
|
||||
) -> Option<AuthData> {
|
||||
if let Some(raw_cookie) = headers.get(http::header::COOKIE) {
|
||||
if let Ok(cookie) = raw_cookie.to_str() {
|
||||
if let Some(ticket) = extract_cookie(cookie, auth_context.auth_cookie_name()) {
|
||||
let csrf_token = match headers.get("CSRFPreventionToken").map(|v| v.to_str()) {
|
||||
Some(Ok(v)) => Some(v.to_owned()),
|
||||
_ => None,
|
||||
};
|
||||
return Some(AuthData::User(UserAuthData { ticket, csrf_token }));
|
||||
}
|
||||
let mut ticket = None;
|
||||
let cookie_name = auth_context.auth_cookie_name();
|
||||
let host_cookie = auth_context.prefixed_auth_cookie_name();
|
||||
let cookies = headers
|
||||
.get_all(http::header::COOKIE)
|
||||
.iter()
|
||||
.filter_map(|c| c.to_str().ok());
|
||||
|
||||
for cookie in cookies {
|
||||
// check if we got a `__Host-` prefixed cookie first and break the loop if we do so we use
|
||||
// that cookie.
|
||||
if let Some(extracted_ticket) = extract_cookie(cookie, host_cookie) {
|
||||
ticket = Some(extracted_ticket);
|
||||
break;
|
||||
// if no such prefixed cookie exists, try to fall back to a non-prefixed one
|
||||
// TODO: remove this once we do not support less secure non-prefixed cookies anymore
|
||||
} else if let Some(extracted_ticket) = extract_cookie(cookie, cookie_name) {
|
||||
ticket = Some(extracted_ticket)
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ticket) = ticket {
|
||||
let csrf_token = match headers.get("CSRFPreventionToken").map(|v| v.to_str()) {
|
||||
Some(Ok(v)) => Some(v.to_owned()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
return Some(AuthData::User(UserAuthData { ticket, csrf_token }));
|
||||
}
|
||||
|
||||
let token_prefix = auth_context.auth_token_prefix();
|
||||
match headers.get(http::header::AUTHORIZATION).map(|v| v.to_str()) {
|
||||
Some(Ok(v)) => {
|
||||
|
Loading…
Reference in New Issue
Block a user