Skip to content

Commit 3789c9e

Browse files
committed
fix(webhook): validate URL before sending
Skip sending webhook if URL contains unexpanded $VAR or doesn't start with http:// or https://. Logs a warning with job_id and URL.
1 parent d350a5a commit 3789c9e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/actor/job/executor.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,26 @@ pub async fn execute_job(job: &Job, sot_path: &PathBuf, runner: &RunnerConfig) -
111111

112112
let runner_env = load_runner_env_vars(sot_path, runner);
113113
for webhook in &job.webhook {
114-
send_webhook(&webhook.to_url(runner_env.as_ref()), &payload).await;
114+
let url = webhook.to_url(runner_env.as_ref());
115+
if url.contains('$') {
116+
warn!(
117+
target: "rollcron::webhook",
118+
job_id = %job.id,
119+
url = %url,
120+
"Webhook URL contains unexpanded variable, skipping"
121+
);
122+
continue;
123+
}
124+
if !url.starts_with("http://") && !url.starts_with("https://") {
125+
warn!(
126+
target: "rollcron::webhook",
127+
job_id = %job.id,
128+
url = %url,
129+
"Webhook URL must start with http:// or https://, skipping"
130+
);
131+
continue;
132+
}
133+
send_webhook(&url, &payload).await;
115134
}
116135
}
117136

src/config.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,4 +1025,17 @@ jobs:
10251025
"https://discord.com/api/webhooks/from_env"
10261026
);
10271027
}
1028+
1029+
#[test]
1030+
fn webhook_undefined_env_var_kept_as_is() {
1031+
let env_vars = HashMap::new(); // empty
1032+
1033+
let webhook = WebhookConfig {
1034+
webhook_type: "discord".to_string(),
1035+
url: "$UNDEFINED_VAR".to_string(),
1036+
};
1037+
1038+
// Undefined vars are kept as-is (caller should validate)
1039+
assert_eq!(webhook.to_url(Some(&env_vars)), "$UNDEFINED_VAR");
1040+
}
10281041
}

0 commit comments

Comments
 (0)