Skip to content

fix(tinyredact): reject an IBAN candidate with non-ASCII digits instead of panicking - #315

Open
shaurya703 wants to merge 1 commit into
tinyhumansai:mainfrom
shaurya703:fix/iban-non-ascii-digit-panic
Open

shaurya703 wants to merge 1 commit into
tinyhumansai:mainfrom
shaurya703:fix/iban-non-ascii-digit-panic

Conversation

@shaurya703

@shaurya703 shaurya703 commented Oct 26, 2026 •

Copy link
Copy Markdown

Summary

tinyredact's IBAN validator panics on a candidate whose check digits come from a non-Latin script, which crashes redact_pii, has_likely_pii and the default sanitize policy on ordinary user text.

Bug. IBAN_RE ([A-Z]{2}\d{2}(?:[\s]?[A-Z0-9]){11,30}) uses Unicode \d, so it matches Devanagari, Bengali and other decimal digits. Normalization only folds fullwidth and Arabic-Indic digits, so these reach valid_iban unchanged. Reproduction on current main:

tinyredact::redact_pii("IBAN DE४४1234567890123456 end");
// panicked at crates/tinyredact/src/pii/checks.rs:181:16:
// end byte index 4 is not a char boundary; it is inside '४' (bytes 2..5 of string)

Root cause. valid_iban checks the length in bytes and slices cleaned[2..4] by byte offset, assuming the candidate is ASCII. A multi-byte digit at position 2 makes index 4 fall inside a character.

Fix. An IBAN is ASCII by definition, so valid_iban now rejects any candidate that is not ASCII alphanumeric after whitespace removal, before the slicing. Valid IBANs are unaffected.

Related issue

None. Found while reading the PII validators.

API or behavior changes

None for valid input. Text that used to panic now passes through unchanged.

Validation

  • cargo fmt --all -- --check: clean
  • cargo clippy -p tinyredact --all-targets --all-features -- -D warnings: clean
  • cargo test -p tinyredact: 211 passed (the two new tests panic without the fix)

Tests

  • pii::checks::tests::iban_rejects_non_ascii_digits_without_panicking: calls the validator directly with Devanagari check digits.
  • pii::tests::iban_with_non_ascii_digits_does_not_panic: runs the public redact_pii (content) and has_likely_pii (boundary) paths on the same text and expects it left alone.

Documentation

Not needed. A comment on valid_iban explains the guard.

Checklist

  • The change is focused on one logical change
  • No new #[allow(...)], #[ignore], or relaxed lints
  • No secrets, tokens, or .env contents in the diff or the description

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of IBAN-like text containing non-ASCII digits. These inputs are now rejected safely without causing a crash, and remain unchanged during PII processing.
    • IBAN validation now rejects candidates containing non-ASCII characters or ASCII punctuation before further validation.

…ad of panicking

IBAN_RE matches with Unicode \d, so a run such as "DE४४1234567890123456"
(Devanagari check digits, which normalization does not fold) reaches
valid_iban. It sliced the check digits as cleaned[2..4] by byte offset,
which splits the three-byte digit and panics. redact_pii and
has_likely_pii both run the IBAN rule, so any text of that shape crashed
the redactor.

An IBAN is ASCII by definition: reject any candidate that is not ASCII
alphanumeric after whitespace removal, before the slicing.
@tinysweeper

tinysweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Tiny Sweeper review

Reviewed head: 70e22044385bac3774eeb3d3e7d33081ae6a2170

Verdict: Ready for maintainer review · Priority: none
Coverage: Reviewed 3 of 3 files.
Pull request purpose (title): fix(tinyredact): rej…

Diagnostics and supporting details

Full summary

Pull request purpose (title): fix(tinyredact): reject an IBAN candidate with non-ASCII digits instead of panicking. `valid_iban` in tinyredact could panic on an IBAN candidate whose check digits come from a non-Latin script: `IBAN_RE` uses Unicode `\d`, normalization does not fold Devanagari/Bengali digits, and `valid_iban` sliced `cleaned[2..4]` by byte offset, splitting a multi-byte digit. This pull request adds an ASCII-alphanumeric guard before length checks and slicing so such candidates are rejected and the text passes through unchanged, with new tests at the validator level and on the public redaction/boundary paths.

Review snapshot

Change surface Files Review signal Count
Production 1 Active findings 0
Tests 2 Noted findings 0
Documentation 0 Resolved findings 0
Configuration 0 Pending checks/questions 0

Completeness: Complete
Test assessment: Test coverage is assessed from changed tests and lane evidence; execution is not claimed without trusted check data.

What changed

`valid_iban` in `crates/tinyredact/src/pii/checks.rs` now returns false for any candidate containing a character that is not ASCII alphanumeric after whitespace removal, placed before the length check and the byte-offset slicing that previously assumed ASCII. A comment documents the Unicode-`\d` mismatch in `IBAN_RE`. Two tests are added: `iban_rejects_non_ascii_digits_without_panicking` in `crates/tinyredact/src/pii/checks_tests.rs` calls the validator directly with Devanagari check digits (leading and mid-string), and `iban_with_non_ascii_digits_does_not_panic` in `crates/tinyredact/src/pii/mod_tests.rs` asserts the text is left unchanged and `has_likely_pii` is false. Valid IBANs are unaffected.

Features

  • Modified — `valid_iban` rejects non-ASCII candidates before byte-offset slicing: Candidate strings containing non-ASCII characters (e.g. Devanagari digits that `IBAN_RE` matches via Unicode `\d`) now return false instead of panicking on a non-char-boundary slice; ASCII IBAN validation behavior is unchanged. (crates/tinyredact/src/pii/checks.rs pub(crate) fn plausible_card_number(d: &[u32]) -> bool {)
  • Added — Validator-level regression test for non-ASCII IBAN digits: Pins that `valid_iban` returns false (rather than panicking) for candidates with Devanagari digits in the check-digit positions. (crates/tinyredact/src/pii/checks_tests.rs fn payment_checksums_reject_bad_bounds_and_checksums() {)

Tests

  • unit — Calls `valid_iban` with candidates `DE४४1234567890123456` and `DE89४70400440532013000`, expecting false without panicking.: Tests the validator directly at the layer where the bug occurred; the pull-request description states it panicked before the fix. Per the tests lane, this provides a failing-before test for the validator path; no execution evidence is available in the review evidence. (crates/tinyredact/src/pii/checks_tests.rs fn payment_checksums_reject_bad_bounds_and_checksums() {)
  • integration — Runs the public `redact_pii` content path and `has_likely_pii` boundary path on `"IBAN DE४४1234567890123456 end"`, asserting the text is unchanged and no likely PII is reported.: Covers both crash paths through public APIs and asserts observable behavior rather than internal calls. (crates/tinyredact/src/pii/mod_tests.rs fn iban_de_redacted() {)

Findings

No active actionable findings.

Before merge

None.

Agent review details

critique

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: Reviewed 3 files; 0 findings. _The code index is behind this pull request (indexed at `0ab030f90752`), so retrieved context may be out of date._

security

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: Reviewed 3 files; 0 findings. _The code index is behind this pull request (indexed at `0ab030f90752`), so retrieved context may be out of date._

tests

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: The change adds a real guard in `valid_iban` against non-ASCII characters reaching the byte-offset slicing, and both the validator-level test (`checks_tests.rs`) and the end-to-end redaction/boundary test (`mod_tests.rs`) pin the previously-panicking Devanagari input, so the fix has a failing-before test on both paths. The tests assert behaviour (rejection and unchanged output), not mock calls, and no new branch is left uncovered. Looks sound. _The code index is behind this pull request (indexed at `0ab030f90752`), so retrieved context may be out of date._

commits

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The commits lane found no sensitive content in committed files.
  • Lane summary: No sensitive content in committed files. _The code index is behind this pull request (indexed at `0ab030f90752`), so retrieved context may be out of date._

description

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The description matches the diff: an ASCII guard in `valid_iban` before the byte-offset slicing, two tests, and an explanatory comment; the description lane found no defects.
  • Lane summary: The description matches the diff: an ASCII guard added to `valid_iban` before the byte-offset slicing, with two tests on the validator and the public paths, and a comment explaining the guard. Test placement follows the repository's `checks_tests.rs` convention. No defects found. _The code index is behind this pull request (indexed at `0ab030f90752`), so retrieved context may be out of date._
Evidence and run details
  • Models: ladder/vectors-oai3, deepseek-v4.1-flash
  • Spend: $0.000263
  • Tokens: 211179 input · 3928 output · 77312 cached · 197 embedding
  • Updated: 2026-10-26T06:24:02Z
Head State Pass summary
70e22044385b ready for maintainer review 0 active finding(s), 0 resolved finding(s) (at 2026-10-26T06:24:02Z)

tinysweeper 0.1.2

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 94a76e15-67d7-4f08-9333-cee5d64472c8
Commits

Reviewing files that changed from the base of the PR and between 8b919fd and 70e2204.

Files selected for processing: 3
  • crates/tinyredact/src/pii/checks.rs
  • crates/tinyredact/src/pii/checks_tests.rs
  • crates/tinyredact/src/pii/mod_tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

valid_iban now rejects candidates with non-ASCII-alphanumeric bytes before length checks and byte-offset slicing. Regression tests cover Devanagari digits, including that PII detection leaves an IBAN-like input unchanged and does not flag it.

Changes: IBAN validation

Layer / File(s) Summary
ASCII validation and regression coverage
crates/tinyredact/src/pii/checks.rs, crates/tinyredact/src/pii/checks_tests.rs, crates/tinyredact/src/pii/mod_tests.rs
valid_iban rejects non-ASCII-alphanumeric candidates before length checks and byte-offset slicing. Tests check rejection of Devanagari digits, unchanged input, and a false result from has_likely_pii.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: senamakel

Merge Risk: Minimal · up to 70e22

No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly states the main change: reject IBAN candidates with non-ASCII digits to prevent a panic. It is specific, concise, and directly matches the implementation and regression tests.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the IBAN line,
And keeps each byte within its sign.
No split digit can cause a fall,
The tests now guard the path for all.
The rabbit hops, pleased with the call.

Comment @coderabbitai help to get the list of available commands.

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tinysweeper found nothing blocking. Approving.

Diagnostics

Total spend: $0.0003

@tinysweeper tinysweeper Bot added the priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect. label Oct 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant