Sensitive data
Deny requests that contain data that should never reach you.
This rule spots sensitive data in a request body or in a text you give it: card numbers, IBANs, API keys, JWTs, private keys… It prevents, for example, a user from pasting their card number into a comment field, or a secret from being sent to an AI model.
The problem
Data that should never pass through your application still ends up in your requests: a customer pasting their card number into a comment field, a user sending an API key in a support ticket, a secret passed to an AI model. Once stored in your database, your logs or at a provider, this data becomes a leak to deal with.
What it stops
- card numbers and IBANs;
- API keys (including Wave, Flutterwave and Paystack), JWTs and private keys;
- secrets sent to an AI model.
When to use it
Free-text fields (comments, support, messaging), APIs that receive content from your users, messages sent to an AI.
And in your responses?
This rule inspects what comes into your application. To mask sensitive data that would leave by mistake in your responses, use the responseGuard option: see SDK options.
Configuration
import express from "express";
import { zarex, sensitiveInfo } from "@zarex/express";
const app = express();
app.use(express.json());
app.use(
zarex({
key: process.env.ZAREX_KEY!,
rules: [sensitiveInfo()],
})
);With no option, secrets are denied: CREDIT_CARD, SSN, API_KEY, JWT, PRIVATE_KEY and IBAN.
Detected types
| Type | What is recognized |
|---|---|
CREDIT_CARD | Card number, with or without spaces. The issuer prefix and the check digit (Luhn) are verified: a random 16-digit number is not a card. |
IBAN | International bank account number, in upper or lower case. The check digits are verified. |
API_KEY | Known API keys: AWS, GitHub, Stripe and Paystack (sk_live_…), Slack, Google, OpenAI, Anthropic, SendGrid, Twilio, Wave, Flutterwave, Zarex. A public key (pk_…, FLWPUBK…) is not a secret and is not counted. |
JWT | JWT token (eyJ….eyJ….…). |
PRIVATE_KEY | Private key (-----BEGIN … PRIVATE KEY-----). |
SSN | US Social Security number (123-45-6789). |
EMAIL | Email address. |
PHONE | International-format number (+229…, 00229…), or a 10-digit local number starting with 0 (01 97 12 34 56). |
PASSWORD | A value written after a word such as password, mot de passe, mdp, pwd or secret: password: …, "mdp": "…". |
HIGH_ENTROPY | A random value placed after a word such as secret, token or api_key, whose format is unknown (an MTN MoMo key, for example). |
Invisible characters slipped into a value (zero-width spaces) do not prevent detection.
EMAIL, PHONE and PASSWORD on request
These three types are only denied if you add them to deny: a sign-up or login form legitimately contains them. HIGH_ENTROPY can produce more false positives: try it in DRY_RUN first.
PASSWORD and login forms
With PASSWORD in deny, the "password" field of a login or sign-up form is itself recognized, and the request denied. Only apply this type to routes where a password has no business: comments, support, messages sent to an AI.
Options
| Option | Values | Default | Role |
|---|---|---|---|
deny | types above | CREDIT_CARD, SSN, API_KEY, JWT, PRIVATE_KEY, IBAN | Denied types. deny replaces the default list: write it in full. |
inspect | "body" · "text_content" | both | Where to look: the request body, and a text given with call: () => ({ text }). |
oversize | "deny" · "inspect" · "allow" | "inspect" | What to do with an input that is too large (body over 48 KB, text over 32 KB). "inspect" inspects the beginning and the end. |
mode | "LIVE" · "DRY_RUN" · "OFF" | "LIVE" | Deny, only observe, or disable. |
The body is sent by default since 0.2.0 (inspectBody: true). If you turned it off, only the text given by call is inspected.
Inspect a text meant for an AI
rules: [sensitiveInfo({ inspect: ["text_content"] })],
call: (req) => ({ text: req.body.message }),An AWS key pasted into the message (here is my key AKIA…) is then denied before it reaches the model.
mode: observe before blocking
In DRY_RUN, nothing is blocked: the decision log shows the types that would have been denied, and how many times. Useful before adding HIGH_ENTROPY, EMAIL or PHONE.
What the decision contains
The rule's result, in decision.results (ruleType: "SENSITIVE_INFO"), contains in reason:
| Field | Meaning |
|---|---|
detected | true: at least one requested type of sensitive data was found. |
types | The types found. |
counts | The number of occurrences of each type. |
truncated | true: the input was too large, only the beginning and the end were inspected. |
skipped | "no_content": there was nothing to inspect. |
The value found never appears in the decision or in the decision log: only its type and count. The result does not become a leak itself.
Example, a message that contains a Stripe key and a JWT:
{ "detected": true, "types": ["API_KEY", "JWT"], "counts": { "API_KEY": 1, "JWT": 1 } }