Skip to content

Commit fd62274

Browse files
authored
Merge pull request #3152 from itowlson/allowed-hosts-explain-why-not
Provide more guidance on invalid `allowed_outbound_hosts`
2 parents 960490d + 70c2020 commit fd62274

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

crates/factor-outbound-networking/src/allowed_hosts.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,12 @@ impl AllowedHostConfig {
9191
pub fn parse(url: impl Into<String>) -> anyhow::Result<Self> {
9292
let original = url.into();
9393
let url = original.trim();
94-
let (scheme, rest) = url.split_once("://").with_context(|| {
95-
format!("{url:?} does not contain a scheme (e.g., 'http://' or '*://')")
96-
})?;
94+
let Some((scheme, rest)) = url.split_once("://") else {
95+
match url {
96+
"*" | ":" | "" | "?" => bail!("{url:?} is not an allowed outbound host format.\nHosts must be in the form <scheme>://<host>[:<port>], with '*' wildcards allowed for each.\nIf you intended to allow all outbound networking, you can use '*://*:*' - this will obviate all network sandboxing.\nLearn more: https://spinframework.dev/v3/http-outbound#granting-http-permissions-to-components"),
97+
_ => bail!("{url:?} does not contain a scheme (e.g., 'http://' or '*://')\nLearn more: https://spinframework.dev/v3/http-outbound#granting-http-permissions-to-components"),
98+
}
99+
};
97100
let (host, rest) = rest.rsplit_once(':').unwrap_or((rest, ""));
98101
let port = match rest.split_once('/') {
99102
Some((port, path)) => {

0 commit comments

Comments
 (0)