log-pii-redactor

Find and mask personal data and secrets inside log lines: IP, USER, EMAIL, HOST, PHONE, SECRET (API keys, tokens, JWTs), CARD, MAC, SSN. A small (82M parameter) token classifier plus a rule-based clean-up, for sharing or storing logs (support tickets, SIEM exports, LLM log analysis). It reads usernames and hostnames in context across syslog, Apache, Java-style and Windows event JSON layouts, which a regex cannot do, and runs on CPU or in your browser with no server.

Try it in your browser: a static page that runs the model locally (transformers.js, ONNX, WebAssembly). The text you paste never leaves your device.

Results

OTRF Security-Datasets (MIT): 540 single-line Windows Security / Sysmon / PowerShell JSON events from 12 lab-emulated attack datasets. Gold comes from explicit event fields: IP = IpAddress/SourceIp/DestinationIp/... values that parse as IPv4 or IPv6 (84 spans); USER = TargetUserName/SubjectUserName/User/... excluding service and machine accounts (86 spans); HOST = Computer/Hostname/WorkstationName/... (543 spans). Exact-span match, F1.

System IP F1 USER F1 HOST F1
log-pii-redactor v0.2, model only (ip_regex=False) 0.952 0.734 0.963
log-pii-redactor v0.2, default (ip_regex=True) 0.884 0.734 0.963
log-pii-redactor v0.1 (revision="v0.1.1") 0.934 0.144 0.566
Regex (IPv4 only) 0.705 – –

(– : a regex has no rule for this label.)

Usage

pip install transformers torch huggingface_hub
python - <<'PY'
from huggingface_hub import snapshot_download
import sys; p = snapshot_download("Project-Bastion/log-pii-redactor"); sys.path.insert(0, p)
from redact import detect, redact
line = "Dec 10 06:55:46 LabSZ sshd[24200]: Invalid user webmaster from 173.234.31.186"
print(redact(line, p))   # Dec 10 06:55:46 [HOST] sshd[24200]: Invalid user [USER] from [IP]
print(detect(line, p))   # [(start, end, label, value), ...]
PY

redact.py runs the model and then a small rule-based clean-up (postproc.py): spans snap to token boundaries, ports are stripped, and each type is validated (IPs must parse, card numbers need 13-19 digits, SSN/MAC patterns). Use redact.py rather than the raw model through a transformers pipeline. Options: postprocess=False shows the raw model; ip_regex=False turns off the validated-regex IP fallback that is on by default (it recovers IPs the model misses on some syslog-style formats, and adds some extra IPs on Windows event JSON).

Files

onnx/model_quantized.onnx (int8, ~82 MB, demo default) and onnx/model.onnx (fp32, ~326 MB); the JS port of the clean-up rules is in the demo Space. fp32 ONNX plus the JS pipeline reproduces the Python pipeline span for span on 310 test lines; int8 differs on about 2% of lines, so use fp32 when you need exact agreement. Training data: the synthetic dataset Project-Bastion/log-pii-synthetic (v0.2/). The v0.1.1 weights stay available as revision="v0.1.1".

Limits

  • Pair it with a regex for IPv4 and e-mail addresses, and review USER tags on Windows events (precision about 0.65) before sharing logs externally.
  • English single log lines up to 512 tokens; SECRET, PHONE, CARD and SSN rules are checked on synthetic data only.

License and credits

Apache-2.0. Base model: distilroberta-base (Apache-2.0). Windows event data: OTRF Security-Datasets (MIT). LogHub samples (He et al., Loghub: A Large Collection of System Log Datasets for AI-driven Log Analytics, ISSRE 2023; Zhu et al., Tools and Benchmarks for Automated Log Parsing, ICSE-SEIP 2019) are free for research or academic use and are not redistributed here.

Downloads last month
155
Safetensors
Model size
81.5M params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for Project-Bastion/log-pii-redactor

Quantized
(25)
this model

Space using Project-Bastion/log-pii-redactor 1

Evaluation results

  • IP exact-span F1 (default pipeline with IP fallback; model-only 0.952) on OTRF Security-Datasets
    self-reported
    0.884
  • USER exact-span F1 on OTRF Security-Datasets
    self-reported
    0.734
  • HOST exact-span F1 on OTRF Security-Datasets
    self-reported
    0.963