Base64 URL path segments

Unknown data in URL paths can result in invalid URLs, but base64url is designed to be URL-safe.


Use this solution in your VCL service (click RUN below to test this solution or clone it to make changes):


Use this solution in your Compute@Edge service:

  1. Rust
lazy_static! {
static ref RE: Regex = Regex::new(r"/views/(?P<path>[^/]*)").unwrap();
let url = "/views/zqzOu8-GzrE=/path/filename.html";
if let Some(encoded) = RE
.map(|p| p.as_str().to_owned())
let decoded = base64::decode_config(encoded, base64::URL_SAFE)?;
assert_eq!(decoded, "άλφα".as_bytes());
// When base64-encoded material is sent as a part of a URL, the `encode_config` and
// `decode_config` functions should be used, specifying that we want to use a character
// set that is safe for use in URL's.
// `URL_SAFE_NO_PAD` can also be used to omit `=` padding. For example, the segment path
// in this demo is encoded like this:
"from=06/07/2013 query=\"Καλώς ορίσατε\"",
// The normal base64 encoding of this text would include characters invalid in a URL path.
// See below:
base64::encode_config("from=06/07/2013 query=\"Καλώς ορίσατε\"", base64::STANDARD),