chore: treat the workspace webhook URL as a settings secret (#12414)

* chore: treat the workspace webhook URL as a settings secret

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep the webhook when pushing settings to a server storing it plain

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: reattach applySettingsDocument doc comment

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-11-13 14:36:43 +01:00
committed by GitHub
co-authored by Claude Opus 5.5
parent b2793f2aca
commit 6592005d87
7 changed files with 94 additions and 36 deletions
File diff suppressed because one or more lines are too long
@@ -41,7 +41,8 @@ use crate::db::ApiAuthed;
pub const SENSITIVE_UNCHANGED: &str = "__SENSITIVE_AND_UNCHANGED__";
use windmill_common::variables::SETTINGS_ENCRYPTED_PREFIX as ENCRYPTED_PREFIX;
const SECRET_KEYS: &[&str] = &["slack_oauth_client_secret"];
/// The webhook URL is a secret because it usually carries the receiver's token.
const SECRET_KEYS: &[&str] = &["webhook", "slack_oauth_client_secret"];
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Default)]
#[serde(rename_all = "snake_case")]
@@ -366,17 +367,21 @@ pub async fn load_settings_document(
.fetch_one(&mut *conn)
.await?;
let slack_oauth_client_secret = match (row.slack_oauth_client_secret, secrets) {
(Some(s), SecretMode::Redacted) if !s.is_empty() => Some(SENSITIVE_UNCHANGED.to_string()),
(Some(s), SecretMode::Encrypted) if !s.is_empty() => {
let mc = build_crypt(db, w_id).await?;
Some(format!(
"{ENCRYPTED_PREFIX}{}",
mc.encrypt_str_deterministic(&s)
))
}
let mc = match secrets {
SecretMode::Encrypted => Some(build_crypt(db, w_id).await?),
_ => None,
};
let secret = |v: Option<String>| match (v, &mc) {
(Some(s), _) if s.is_empty() => Some(s),
(Some(s), Some(mc)) => Some(format!(
"{ENCRYPTED_PREFIX}{}",
mc.encrypt_str_deterministic(&s)
)),
(Some(_), None) if secrets == SecretMode::Redacted => Some(SENSITIVE_UNCHANGED.to_string()),
(s, _) => s,
};
let webhook = secret(row.webhook);
let slack_oauth_client_secret = secret(row.slack_oauth_client_secret);
let has_permissions = row
.datatable
@@ -413,7 +418,7 @@ pub async fn load_settings_document(
// added since is always written, so a pulled file states it and from then on manages it.
let entries: [(&str, Option<Value>, bool); 33] = [
("auto_invite", row.auto_invite, false),
("webhook", row.webhook.map(Value::String), false),
("webhook", webhook.map(Value::String), false),
("webhook_events", row.webhook_events.map(|e| json!(e)), true),
("error_handler", row.error_handler, true),
("success_handler", row.success_handler, true),
@@ -2252,25 +2257,27 @@ mod tests {
#[test]
fn secrets_keep_their_value_for_the_placeholder_and_a_foreign_key() {
let mc = WorkspaceCrypt::new("k");
let ours = format!(
"{ENCRYPTED_PREFIX}{}",
mc.encrypt_str_deterministic("sekret")
);
let theirs = format!(
"{ENCRYPTED_PREFIX}{}",
WorkspaceCrypt::new("other").encrypt_str_deterministic("x")
);
for secret in [SENSITIVE_UNCHANGED.to_string(), ours, theirs.clone()] {
let p = plan_document(
current(),
doc(json!({ "slack_oauth_client_secret": secret })),
false,
&mc,
&DatatableNames::default(),
)
.unwrap();
assert!(p.changes.is_empty(), "{secret}: {:?}", keys(&p));
assert_eq!(p.warnings.len(), usize::from(secret == theirs));
for (key, stored) in [
("slack_oauth_client_secret", "sekret"),
("webhook", "https://a"),
] {
let ours = format!("{ENCRYPTED_PREFIX}{}", mc.encrypt_str_deterministic(stored));
for secret in [SENSITIVE_UNCHANGED.to_string(), ours, theirs.clone()] {
let p = plan_document(
current(),
doc(json!({ key: secret })),
false,
&mc,
&DatatableNames::default(),
)
.unwrap();
assert!(p.changes.is_empty(), "{key} {secret}: {:?}", keys(&p));
assert_eq!(p.warnings.len(), usize::from(secret == theirs));
}
}
}
+52 -5
View File
@@ -232,6 +232,20 @@ export async function pushWorkspaceSettings(
delete localSettings.datatable_permissions;
}
if (
unreadableSecret(localSettings.webhook) &&
!(await documentKeepsRedactedWebhook(workspace))
) {
log.warn(
"Leaving the webhook unchanged: this server stores the webhook URL in plain text and cannot read an encrypted or redacted one. Upgrade it, or write the URL in plain text."
);
const remote = await wmill.getWorkspaceSettingsDocument({ workspace });
if (typeof remote.webhook === "string") {
localSettings.webhook = remote.webhook;
} else {
delete localSettings.webhook;
}
}
if (await applySettingsDocument(workspace, localSettings)) {
return;
}
@@ -240,10 +254,13 @@ export async function pushWorkspaceSettings(
for (const key of SETTINGS_MANAGED_ONLY_WHEN_PRESENT) {
delete (localSettings as any)[key];
}
const secret = localSettings.slack_oauth_client_secret;
const slackSecretUnreadable =
typeof secret === "string" &&
(secret.startsWith("$encrypted:") || secret === "__SENSITIVE_AND_UNCHANGED__");
const webhookUnreadable = unreadableSecret(localSettings.webhook);
if (webhookUnreadable) {
log.warn(
"Leaving the webhook unchanged: this server cannot read an encrypted or redacted webhook URL. Upgrade it, or write the URL in plain text."
);
}
const slackSecretUnreadable = unreadableSecret(localSettings.slack_oauth_client_secret);
if (slackSecretUnreadable) {
log.warn(
"Leaving the Slack OAuth client and secret unchanged: this server cannot read an encrypted or redacted secret. Upgrade it, or write the secret in plain text."
@@ -301,7 +318,7 @@ export async function pushWorkspaceSettings(
}
log.debug(`Workspace settings are not up-to-date, updating...`);
if (localSettings.webhook !== settings.webhook) {
if (!webhookUnreadable && localSettings.webhook !== settings.webhook) {
log.debug(`Updating webhook...`);
await wmill.editWebhook({
workspace,
@@ -550,6 +567,36 @@ export async function pushWorkspaceSettings(
}
}
function unreadableSecret(secret: unknown): boolean {
return (
typeof secret === "string" &&
(secret.startsWith("$encrypted:") || secret === "__SENSITIVE_AND_UNCHANGED__")
);
}
/**
* Whether the settings document treats the webhook URL as a secret: a server whose document
* predates that plans the placeholder as a new URL, which its webhook endpoint then refuses.
* True for a server without the document, whose fallback path handles the secret itself.
*/
async function documentKeepsRedactedWebhook(workspace: string): Promise<boolean> {
try {
const result = await wmill.applyWorkspaceSettingsDocument({
workspace,
requestBody: {
document: { webhook: "__SENSITIVE_AND_UNCHANGED__" },
dry_run: true,
},
});
return !result.changes.some((c) => c.key === "webhook");
} catch (err: any) {
if (err?.status === 404 && !err?.body) {
return true;
}
throw new Error(`Failed to read workspace settings: ${err?.body ?? err}`);
}
}
/** Applies settings.yaml server-side, which owns the rules for what an omitted or null setting
* means. Returns false on a server that predates the settings document. */
async function applySettingsDocument(
+2 -1
View File
@@ -8504,7 +8504,8 @@ read or change it.
## Secrets
\`slack_oauth_client_secret\` is the one secret. A read shows \`__SENSITIVE_AND_UNCHANGED__\` in place
\`webhook\` (its URL usually carries the receiver's token) and \`slack_oauth_client_secret\` are the
secrets. A read shows \`__SENSITIVE_AND_UNCHANGED__\` in place
of a set secret; sending that placeholder back keeps the stored value. A value starting with
\`$encrypted:\` is decrypted with the workspace key, and one encrypted with another workspace's key
is left unchanged with a warning; any other value is taken as plaintext. Never
+2 -1
View File
@@ -1611,7 +1611,8 @@ read or change it.
## Secrets
\`slack_oauth_client_secret\` is the one secret. A read shows \`__SENSITIVE_AND_UNCHANGED__\` in place
\`webhook\` (its URL usually carries the receiver's token) and \`slack_oauth_client_secret\` are the
secrets. A read shows \`__SENSITIVE_AND_UNCHANGED__\` in place
of a set secret; sending that placeholder back keeps the stored value. A value starting with
\`$encrypted:\` is decrypted with the workspace key, and one encrypted with another workspace's key
is left unchanged with a warning; any other value is taken as plaintext. Never
@@ -27,7 +27,8 @@ read or change it.
## Secrets
`slack_oauth_client_secret` is the one secret. A read shows `__SENSITIVE_AND_UNCHANGED__` in place
`webhook` (its URL usually carries the receiver's token) and `slack_oauth_client_secret` are the
secrets. A read shows `__SENSITIVE_AND_UNCHANGED__` in place
of a set secret; sending that placeholder back keeps the stored value. A value starting with
`$encrypted:` is decrypted with the workspace key, and one encrypted with another workspace's key
is left unchanged with a warning; any other value is taken as plaintext. Never
+2 -1
View File
@@ -22,7 +22,8 @@ read or change it.
## Secrets
`slack_oauth_client_secret` is the one secret. A read shows `__SENSITIVE_AND_UNCHANGED__` in place
`webhook` (its URL usually carries the receiver's token) and `slack_oauth_client_secret` are the
secrets. A read shows `__SENSITIVE_AND_UNCHANGED__` in place
of a set secret; sending that placeholder back keeps the stored value. A value starting with
`$encrypted:` is decrypted with the workspace key, and one encrypted with another workspace's key
is left unchanged with a warning; any other value is taken as plaintext. Never