-
-
Notifications
You must be signed in to change notification settings - Fork 80
[SEC] restrict CORS to authorized extension IDs #581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,5 @@ NDK | |
| *.sqlite* | ||
| *.db | ||
| *.db-journal | ||
|
|
||
| .vscode | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,11 +127,55 @@ fn get_file(file: PathBuf, state: &State<ServerState>) -> Option<(ContentType, V | |
| Some((content_type, asset)) | ||
| } | ||
|
|
||
| pub fn build_rocket(server_state: ServerState, config: AWConfig) -> rocket::Rocket<rocket::Build> { | ||
| pub fn build_rocket( | ||
| server_state: ServerState, | ||
| mut config: AWConfig, | ||
| ) -> rocket::Rocket<rocket::Build> { | ||
| info!( | ||
| "Starting aw-server-rust at {}:{}", | ||
| config.address, config.port | ||
| ); | ||
| { | ||
| let db = server_state.datastore.lock().unwrap(); | ||
| let parse_cors_list = |raw: &str| -> Vec<String> { | ||
| serde_json::from_str::<String>(raw) | ||
| .unwrap_or_else(|_| raw.trim_matches('"').to_string()) | ||
| .split(',') | ||
| .map(|s| s.trim().to_string()) | ||
| .filter(|s| !s.is_empty()) | ||
| .collect() | ||
| }; | ||
| let parse_bool = |raw: &str| -> bool { | ||
| serde_json::from_str::<bool>(raw).unwrap_or_else(|_| raw.trim_matches('"') == "true") | ||
| }; | ||
| // Sync settings between Config file and Database. | ||
| // On the first run (when a key is missing in the DB), we seed the DB with the value from the config file. | ||
| // On subsequent runs, we always prefer the DB value (which might have been changed via the UI). | ||
|
Comment on lines
+151
to
+153
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems problematic. It's not acceptable to have file-level config options being ignored by auto-set db-values. Makes the config file mostly useless/unreliable. Not really any "sync" happening here. imo, order of settings/config precedence in server should be cli options -> env vars -> config file -> webui/api settings -> defaults. One way to resolve this would be to make the webui config write directly to the config file, would effectively put them in sync (but still not a fan of exposing server config like this in api/webui tbh). But that might require a API endpoint different from Simplest would probably be to just prefer the config over the db settings and disable the webui settings if they are explicitly set in config/env/cli. |
||
| let sync = | ||
| |key: &str, current_val: &mut String, to_save: String| match db.get_key_value(key) { | ||
| Ok(raw) => *current_val = raw, | ||
| Err(_) => { | ||
| db.set_key_value(key, &to_save).ok(); | ||
| *current_val = to_save; | ||
| } | ||
| }; | ||
|
|
||
| let mut raw_cors = String::new(); | ||
| sync("settings.cors", &mut raw_cors, serde_json::to_string(&config.cors.join(",")).unwrap()); | ||
| config.cors = parse_cors_list(&raw_cors); | ||
|
|
||
| let mut raw_cors_regex = String::new(); | ||
| sync("settings.cors_regex", &mut raw_cors_regex, serde_json::to_string(&config.cors_regex.join(",")).unwrap()); | ||
| config.cors_regex = parse_cors_list(&raw_cors_regex); | ||
|
|
||
| let mut raw_chrome = String::new(); | ||
| sync("settings.cors_allow_aw_chrome_extension", &mut raw_chrome, serde_json::to_string(&config.cors_allow_aw_chrome_extension).unwrap()); | ||
| config.cors_allow_aw_chrome_extension = parse_bool(&raw_chrome); | ||
|
|
||
| let mut raw_mozilla = String::new(); | ||
| sync("settings.cors_allow_all_mozilla_extension", &mut raw_mozilla, serde_json::to_string(&config.cors_allow_all_mozilla_extension).unwrap()); | ||
| config.cors_allow_all_mozilla_extension = parse_bool(&raw_mozilla); | ||
| } | ||
| let cors = cors::cors(&config); | ||
| let hostcheck = hostcheck::HostCheck::new(&config); | ||
| let custom_static = config.custom_static.clone(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.