Skip to content

Commit 2ae09f7

Browse files
Thom van Kalkerenjoepio
authored andcommitted
#525 allow origin authentication
1 parent f282a2a commit 2ae09f7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Changes to JS assets are not included here, but in [`atomic-data-browser`'s CHAN
1111
- Give server agent rights to edit all resources, fix issue with accepting invites in private drives #521
1212
- Add cookie based authentication #512
1313
- `Store::all_resources` returns `Iterator` instead of `Vec` #522 #487
14+
- Change authentication order #525
15+
- Fix cookie subject check #525
1416

1517
## [v0.33.1] - 2022-09-25
1618

server/src/helpers.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use actix_web::cookie::Cookie;
44
use actix_web::http::header::{HeaderMap, HeaderValue};
5+
use actix_web::http::Uri;
56
use atomic_lib::authentication::AuthValues;
67
use percent_encoding::percent_decode_str;
78
use std::str::FromStr;
@@ -60,6 +61,16 @@ pub fn get_auth_headers(
6061
}
6162
}
6263

64+
fn origin(url: &str) -> String {
65+
let parsed = Uri::from_str(url).unwrap();
66+
67+
format!(
68+
"{}://{}",
69+
parsed.scheme_str().unwrap(),
70+
parsed.authority().unwrap()
71+
)
72+
}
73+
6374
pub fn get_auth_from_cookie(
6475
map: &HeaderMap,
6576
requested_subject: &String,
@@ -90,7 +101,10 @@ pub fn get_auth_from_cookie(
90101
error_resource: None,
91102
})?;
92103

93-
if auth_values.requested_subject.ne(requested_subject) {
104+
let subject_invalid = auth_values.requested_subject.ne(requested_subject)
105+
&& auth_values.requested_subject.ne(&origin(requested_subject));
106+
107+
if subject_invalid {
94108
return Err(AtomicServerError {
95109
message: format!(
96110
"Wrong requested subject, expected {} was {}",

0 commit comments

Comments
 (0)