pub fn check_public_url(
url: &str,
) -> impl Future<Output = Result<()>> + Send + use<>Expand description
Checks that url may receive webhooks: http(s), no credentials, and a host that is not (and does not resolve to) a private address.
Call it when a user saves an endpoint URL, to answer the form with the
reason; deliver calls it again before each delivery in release
builds, since a name can point elsewhere later. A host name is
resolved with DNS over HTTPS (Cloudflare’s resolver, A and AAAA
records: two subrequests), as a Worker has no resolver of its own. A
DNS change between the check and the delivery (DNS rebinding) is not
caught; Workers cannot reach private networks anyway, so the check
mainly keeps the app from calling itself or its own services.
§Errors
Error::BadRequest (400) with the reason
(“must start with https:// or http://”, “is a private address”, “was
not found”), or Error::Internal when the
resolver cannot be reached.
§Examples
use ocre::{Result, webhooks};
async fn save_endpoint(url: &str) -> Result<()> {
webhooks::check_public_url(url).await?; // 400 "The webhook URL's host 10.0.0.5 is a private address"
Ok(())
}