Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 26 additions & 50 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 63 additions & 14 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use tauri::{
menu::{Menu, MenuItem},
tray::{TrayIconBuilder, TrayIconId},
webview::WebviewWindowBuilder,
AppHandle, Manager,
AppHandle, Manager, Url,
};

pub struct AppHandleWrapper(Mutex<AppHandle>);
Expand Down Expand Up @@ -191,6 +191,17 @@ pub fn handle_first_run() {
}
}

fn build_dashboard_url(port: u16, api_key: Option<&str>) -> Url {
let mut url =
Url::parse(&format!("http://localhost:{port}/")).expect("Failed to parse localhost url");

if let Some(api_key) = api_key.filter(|key| !key.is_empty()) {
url.query_pairs_mut().append_pair("token", api_key);
}

url
}
Comment on lines +194 to +203
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 security Auth credential visible in Rocket access log

Because the credential is passed as a URL query parameter, Rocket will write the full request line — including the token value — to its HTTP access log on every app launch. On a shared or multi-user machine, log files often carry broader read permissions than the config file from which the credential is read, slightly widening the exposure surface.

A common mitigation is for the webui to call history.replaceState to strip the token from the address bar immediately after reading it, so subsequent navigation logs contain only the clean URL. Worth confirming this cleanup is handled in ActivityWatch/aw-webui#806.


pub fn listen_for_lockfile() {
thread::spawn(|| {
let runtime_path = get_runtime_path();
Expand Down Expand Up @@ -538,22 +549,31 @@ pub fn run() {
if testing {
info!("Running in testing mode (port {})", port);
}
let dashboard_api_key = aw_config
.auth
.api_key
.as_deref()
.filter(|key| !key.is_empty());
if dashboard_api_key.is_some() {
info!("Bootstrapping aw-webui API token into dashboard URL");
}
let dashboard_url = build_dashboard_url(port, dashboard_api_key);
tauri::async_runtime::spawn(build_rocket(server_state, aw_config).launch());
let url = format!("http://localhost:{}/", port)
.parse()
.expect("Failed to parse localhost url");
// Create main window programmatically to attach initialization script.
// The script intercepts clicks on external links and opens them in the system
// browser via the open_external Tauri command. This approach works reliably for
// SPA-generated links where on_navigation (which only fires for top-level
// webview navigations) would miss JS-driven internal route changes.
let _main_window =
WebviewWindowBuilder::new(app, "main", tauri::WebviewUrl::External(url))
.title("aw-tauri")
.inner_size(800.0, 600.0)
.visible(false)
.initialization_script(
r#"
let _main_window = WebviewWindowBuilder::new(
app,
"main",
tauri::WebviewUrl::External(dashboard_url),
)
.title("aw-tauri")
.inner_size(800.0, 600.0)
.visible(false)
.initialization_script(
r#"
document.addEventListener('click', function(e) {
var el = e.target;
while (el && el.tagName !== 'A') { el = el.parentElement; }
Expand All @@ -564,9 +584,9 @@ pub fn run() {
}
}, true);
"#,
)
.build()
.expect("Failed to create main window");
)
.build()
.expect("Failed to create main window");
let manager_state = manager::start_manager();

let open = MenuItem::with_id(app, "open", "Open Dashboard", true, None::<&str>)
Expand Down Expand Up @@ -656,3 +676,32 @@ pub fn run() {
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

#[cfg(test)]
mod tests {
use super::build_dashboard_url;

#[test]
fn build_dashboard_url_omits_token_when_auth_disabled() {
assert_eq!(
build_dashboard_url(5600, None).as_str(),
"http://localhost:5600/"
);
}

#[test]
fn build_dashboard_url_ignores_empty_api_keys() {
assert_eq!(
build_dashboard_url(5600, Some("")).as_str(),
"http://localhost:5600/"
);
}

#[test]
fn build_dashboard_url_appends_encoded_token() {
assert_eq!(
build_dashboard_url(5600, Some("secret+ /?=&")).as_str(),
"http://localhost:5600/?token=secret%2B+%2F%3F%3D%26"
);
}
Comment on lines +700 to +706
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Space encoded as +, not %20

query_pairs_mut().append_pair() uses application/x-www-form-urlencoded encoding, so space becomes + in the serialized URL. URLSearchParams in JavaScript correctly decodes + → space, so the round-trip is fine if aw-webui uses new URLSearchParams(location.search).get('token'). However, if it uses decodeURIComponent() (which treats + as a literal plus sign), any credential containing a space would be silently corrupted.

This is mainly a cross-repo concern to confirm with ActivityWatch/aw-webui#806, but it's worth adding a comment above the test noting the +-for-space convention so future readers don't mistake the expected value for a bug.

}