Skip to content

Commit 1aed8c5

Browse files
emmaling27Convex, Inc.
authored andcommitted
Make invalid auth provider urls bad requests (#40621)
GitOrigin-RevId: 7ab3d803dce9143d098aab0e45407c83a4b80e24
1 parent 7816c1e commit 1aed8c5

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

crates/common/src/auth.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
borrow::Cow,
23
str::FromStr,
34
sync::LazyLock,
45
};
@@ -199,7 +200,16 @@ impl TryFrom<SerializedAuthInfo> for AuthInfo {
199200

200201
static PROTOCOL_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^\w+://").unwrap());
201202

203+
fn invalid_provider_domain_url(msg: impl Into<Cow<'static, str>>) -> ErrorMetadata {
204+
ErrorMetadata::bad_request("InvalidProviderDomainUrl", msg)
205+
}
206+
202207
fn deserialize_issuer_url(original_url: String) -> anyhow::Result<IssuerUrl> {
208+
if original_url.starts_with("\"") {
209+
anyhow::bail!(invalid_provider_domain_url(format!(
210+
"Invalid provider domain URL \"{original_url}\": starts with a double quote (\")"
211+
)));
212+
}
203213
let (had_scheme, url) = if PROTOCOL_REGEX.is_match(&original_url) {
204214
(true, original_url.clone())
205215
} else {
@@ -210,16 +220,18 @@ fn deserialize_issuer_url(original_url: String) -> anyhow::Result<IssuerUrl> {
210220
return Ok(parsed_url);
211221
};
212222
if !url.starts_with("https://") {
213-
anyhow::bail!("Invalid provider domain URL \"{original_url}\": must use HTTPS");
223+
anyhow::bail!(invalid_provider_domain_url(format!(
224+
"Invalid provider domain URL \"{original_url}\": must use HTTPS"
225+
)));
214226
}
215227
let parsed_url = IssuerUrl::new(url)?;
216228
// Check if the input really looks like a URL,
217229
// to catch mistakes (e.g. putting random tokens in the domain field)
218230
if !had_scheme && !parsed_url.url().host_str().is_some_and(ends_with_tld) {
219-
anyhow::bail!(
231+
anyhow::bail!(invalid_provider_domain_url(format!(
220232
"Invalid provider domain URL \"{original_url}\": Does not look like a URL (must have \
221233
a scheme or end with a top-level domain)"
222-
);
234+
)));
223235
}
224236

225237
Ok(parsed_url)

0 commit comments

Comments
 (0)