Skip to main content

Module path_matching

Module path_matching 

Source
Expand description

The exclude_paths matcher: the reference core/validation/path_matching.py.

A request path is normalized before it is compared, so an encoded or dot-segmented spelling cannot slip past (or into) an exclusion:

  1. percent-decode runs of %XX as UTF-8, up to four rounds; an invalid UTF-8 run, or a %XX still left after the fourth round, makes the path unmatchable (never excluded);
  2. fold \ to /, drop empty and . segments, resolve .. against the segments seen so far, and treat a ..;param / .;param segment as its dot form.

An exclusion matches the normalized path when it equals it or is a /-bounded prefix of it (/static excludes /static and /static/app.js, never /staticx); an exclusion of / matches every path. Exclusions normalize the same way, and an exclusion that cannot normalize is dropped.

§Example

use guard_core_engine::path_matching::PathExclusions;

let exclusions = PathExclusions::new(["/static", "/docs"]);
assert!(exclusions.is_excluded("/static/app.js"));
assert!(exclusions.is_excluded("/static/../static/app.js"));
assert!(!exclusions.is_excluded("/static/../admin"));
assert!(!exclusions.is_excluded("/staticx"));

Structs§

PathExclusions
The configured exclusions, normalized once.

Functions§

normalize_exclude_paths
normalize_exclude_paths: the entries that normalize, in order.
normalize_url_path
normalize_url_path: the comparable form of a raw request path, None when it cannot be decoded safely.
path_is_excluded
path_is_excluded: normalize both sides and match.
path_matches_exclusions
path_matches_exclusions: the already-normalized path against already-normalized exclusions.