mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-30 00:07:30 +00:00
* fix: clarify session cookie, token scope and MCP selection refusals Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: clarify unresolved references, app, job and integration refusal messages Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): clarify skipped install scripts and add --run-install-scripts to app bundle and dev Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: clarify app isolation, approval, MCP redirect and embedder messages Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: clarify why CUSTOM_INSTANCE_DB is refused as an app input or resource reference Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: bump ee-repo-ref Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: run install scripts on existing node_modules with --run-install-scripts, generic path scope hint Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: match the reworded resource and variable access refusals Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: bump ee-repo-ref Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
4.3 KiB
Rust
94 lines
4.3 KiB
Rust
/*
|
|
* Author: Ruben Fiszel
|
|
* Copyright: Windmill Labs, Inc 2022
|
|
* This file and its contents are licensed under the AGPLv3 License.
|
|
* Please see the included NOTICE for copyright information and
|
|
* LICENSE-AGPL for a copy of the license.
|
|
*/
|
|
|
|
use axum::extract::FromRequestParts;
|
|
use axum::http::{header, request::Parts, Method};
|
|
use axum::Extension;
|
|
use windmill_api_auth::request_site::{self, Foreign};
|
|
use windmill_common::error::Error;
|
|
use windmill_common::users::COOKIE_NAME;
|
|
|
|
use crate::triggers::trigger_helpers::RunnableId;
|
|
|
|
/// Whether a request is a GET from a page of another origin authenticating on the session
|
|
/// cookie alone. A GET handler that runs a script by path resolves it through
|
|
/// [`Self::script_runnable`], which refuses a Hub script on such a request.
|
|
///
|
|
/// The cookie is `SameSite=Lax`, so browsers attach it to top-level GET navigations from any
|
|
/// site, and to every request from a same-site page (a sibling subdomain). A `hub/` path runs
|
|
/// any public Hub script, and an argument written `$var:<path>` or `$res:<path>` is resolved as
|
|
/// the caller before the script sees it: such a GET lets any page pick a generic Hub script and
|
|
/// hand it the victim's secrets, which the job can then send anywhere. What counts as another
|
|
/// origin is decided by [`request_site::foreign_request`].
|
|
///
|
|
/// Workspace scripts and flows are not refused, by choice, so that GET links to them keep
|
|
/// working. That is a scope decision, not a safety property: they still take attacker-chosen
|
|
/// arguments, `$var:` and `$res:` included, resolved as the victim. What bounds the exposure
|
|
/// is that the attacker needs a runnable path and can only run code the workspace deployed.
|
|
///
|
|
/// The cookie is the only ambient credential. A bearer header is explicit, and so is the
|
|
/// `token` query parameter the webhook URLs carry — a cross-origin `EventSource` has no other
|
|
/// way to authenticate, since it cannot set headers. The checks run in `extract_token`'s
|
|
/// order, header before cookie, because that is the order it resolves them in: a request
|
|
/// carrying both a cookie and `token=` authenticates on the cookie and is therefore still
|
|
/// ambient, which is also why a valid `token=` link opened from another site while signed in
|
|
/// is refused. Other methods never get here with the cookie: `extract_token` sets it aside on
|
|
/// a state-changing request from another origin.
|
|
pub struct CrossSiteGetGuard(Option<Foreign>);
|
|
|
|
impl CrossSiteGetGuard {
|
|
pub fn script_runnable(
|
|
&self,
|
|
script: &windmill_common::runnable_ref::RunnableRef,
|
|
) -> windmill_common::error::Result<RunnableId> {
|
|
let runnable_id = RunnableId::from_ref(script);
|
|
let (Some(signal), RunnableId::HubScript(_)) = (&self.0, &runnable_id) else {
|
|
return Ok(runnable_id);
|
|
};
|
|
signal.log("refusing a GET Hub script run on the session cookie");
|
|
Err(Error::PermissionDenied(format!(
|
|
"a GET request from another site cannot run a Hub script with the session cookie, \
|
|
which takes precedence over a `token` query parameter: pass the token in the \
|
|
`Authorization` header, or open the link from the instance itself or from a browser \
|
|
with no Windmill session. {}",
|
|
request_site::TRUSTED_ORIGINS_HINT
|
|
)))
|
|
}
|
|
}
|
|
|
|
impl<S: Send + Sync> FromRequestParts<S> for CrossSiteGetGuard {
|
|
type Rejection = std::convert::Infallible;
|
|
|
|
async fn from_request_parts(
|
|
parts: &mut Parts,
|
|
state: &S,
|
|
) -> std::result::Result<Self, Self::Rejection> {
|
|
if parts.method != Method::GET {
|
|
return Ok(CrossSiteGetGuard(None));
|
|
}
|
|
let Some(signal) = request_site::foreign_request(&parts.headers, &parts.uri) else {
|
|
return Ok(CrossSiteGetGuard(None));
|
|
};
|
|
|
|
let has_bearer = parts
|
|
.headers
|
|
.get(header::AUTHORIZATION)
|
|
.and_then(|v| v.to_str().ok())
|
|
.is_some_and(|v| v.starts_with("Bearer "));
|
|
if has_bearer {
|
|
return Ok(CrossSiteGetGuard(None));
|
|
}
|
|
|
|
let has_session_cookie =
|
|
Extension::<tower_cookies::Cookies>::from_request_parts(parts, state)
|
|
.await
|
|
.is_ok_and(|Extension(cookies)| cookies.get(COOKIE_NAME).is_some());
|
|
Ok(CrossSiteGetGuard(has_session_cookie.then_some(signal)))
|
|
}
|
|
}
|