Skip to main content

Module data_mask

Module data_mask 

Source
Expand description

The data-mask node — masks sensitive fields in the request before they reach loggers or the upstream: query parameters, headers, and JSON body fields can be removed, replaced with a fixed value, or partially rewritten with a regex substitution.

Port of APISIX’s data-mask plugin. Deviations from the Lua original:

  • Body rules support body_format: json only; urlencoded is rejected at config load.
  • Body field selection uses dotted paths (user.cards.0.number), not JSONPath — no $.. recursive descent or wildcards. A leading $. is tolerated and stripped. Purely numeric segments index into arrays.
  • APISIX runs this in the log phase (masking what loggers see); featherbit runs it wherever the node sits in the graph — place it before logging and/or upstream nodes that must not see the raw values.

Structs§

DataMaskPlugin
Masks request query parameters, headers, and JSON body fields according to a list of rules. Masking is best-effort and never fails at execution time: bodies that are absent, non-JSON, or larger than max_body_size simply skip the body rules. The plugin only touches context.request; it never writes context.message or context.errors.
MaskRule 🔒
One masking rule from the request array.

Enums§

Action 🔒
What a rule does to the matched field.
PathSeg 🔒
One segment of a dotted body path.
Target 🔒
Where a rule applies.

Functions§

apply_to_json 🔒
Applies action to the value addressed by path inside a parsed JSON document. Returns true if anything changed. Paths that do not resolve (missing key, out-of-range index, type mismatch) are silently skipped, as are regex actions on non-string values — mirroring the Lua plugin’s warn-and-continue behavior.
apply_to_multimap 🔒
Applies a rule to a multi-valued map (query params or headers). Regex actions run against every value of the field; replace collapses the field to the single configured value.
parse_dotted_path 🔒
Parses a dotted path (user.cards.0.number), tolerating a leading $. or $. Purely numeric segments become array indices. Empty segments (e.g. a..b) are rejected.
parse_rule 🔒
Parses and validates one rule object, compiling regexes and dotted paths.
regex_mask 🔒
Replaces the first regex match in s with replacement (which may use $1-style capture references). Returns true if a match was rewritten.