Skip to content

fix(safety): detect grouped IBANs and validate them with mod-97 - #268

Merged
M3gA-Mind merged 2 commits into
tinyhumansai:mainfrom
shaurya703:fix/iban-grouped-separators
Nov 11, 2026
Merged

M3gA-Mind merged 2 commits into
tinyhumansai:mainfrom
shaurya703:fix/iban-grouped-separators

Conversation

@shaurya703

Copy link
Copy Markdown
Contributor

Closes #260

Summary

The IBAN rule was \b[A-Z]{2}\d{2}[A-Z0-9]{11,30}\b with no validator. Two consequences, both confirmed against the public API on main:

  • GB82 WEST 1234 5698 7654 32, the grouped form an IBAN is ordinarily written in, scanned as level None with no hits and came back from redact_identifiers unchanged.
  • Any two letters, two digits and eleven alphanumerics counted as a strong BankAccount identifier, so a product code or hash fragment with that shape forced level High.

Behaviour change

  • Pattern: \b[A-Za-z]{2}\d{2}(?:[A-Za-z0-9]{11,30}|(?:[ -][A-Za-z0-9]{4}){2,7}(?:[ -][A-Za-z0-9]{1,3})?)\b. Contiguous, or groups of four separated by a space or hyphen with a shorter final group; either case. The two spellings are separate alternatives on purpose: a single (?:[ -]?[A-Za-z0-9]){11,30} would run a contiguous value on into the next word (…765432 please became one candidate and failed validation), which is exactly the shape in the existing test.
  • Validator: is_iban strips separators, upper-cases, requires 15–34 characters, a two-letter country code, two check digits, and a mod-97 remainder of 1 over the rearranged value (ISO 13616). So the rule now rejects GB82WEST12345698765433 (one digit off) and AB12CDEFGHIJKLMNOP, both of which main flags as High.
  • Rule order: the IBAN rule now precedes the card rule. An IBAN's digit groups can contain a Luhn-valid run, and redact_identifiers applies rules in order, so the longer identifier has to claim its span first for the whole value to be replaced. (None of the fixtures here happens to contain a Luhn-valid run, so the order change is defensive rather than a test-visible fix.)
  • Full-span redaction: pay GB82 WEST 1234 5698 7654 32 today → pay [redacted] today, likewise contiguous and DE89 3704 0044 0532 0130 00 today.

Known limit, left as is: a grouped IBAN whose body length is a multiple of four and that is followed by exactly one four-character word (ES91 2100 0418 4502 0005 1332 then) is still swallowed by the greedy group repetition and then rejected by the validator, so it is missed. The regex crate has no lookahead to stop that at the pattern level; handling it would mean letting a validator shrink a candidate, which is a detector-wide change.

Independent of #262 (card boundaries) and of #265 / #267 at the file level.

Verification

cargo fmt --all -- --check
cargo clippy -p tinymemory-api --all-targets --all-features -- -D warnings
cargo test -p tinymemory-api --features local-safety -- safety     # 36 passed

New tests: grouped and lower-case detection at level High for GB82 (space and hyphen), DE89 and FR76 examples; bad-checksum and random-shape values not flagged; full-span redaction for grouped, contiguous and a grouped value followed by a word; is_iban unit cases (valid contiguous, grouped, lower-case; one digit off; digit in the country code; too short). On main every grouped and lower-case case and both bad-checksum cases fail.

The IBAN rule only matched a contiguous upper-case value, so the form
an IBAN is ordinarily written in, `GB82 WEST 1234 5698 7654 32`, scanned
as level None and came back from redaction unchanged. The rule also had
no validator, so any two letters, two digits and eleven alphanumerics
in a row counted as a bank account.

The pattern now accepts the contiguous spelling or groups of four with a
space or hyphen between them and a shorter final group, in either case,
and `is_iban` checks the ISO 13616 mod-97 remainder over the value with
its separators removed. The two spellings are separate alternatives so
the grouped one cannot run on into the word after a contiguous value.

The rule moves ahead of the card rule: an IBAN's digit groups can hold a
Luhn-valid run, and redaction applies rules in order, so the longer
identifier has to claim its span first for the whole value to be
replaced.

Closes tinyhumansai#260
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 2 billable files and costs up to $0.50.

Or wait 59 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

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: 9e4a80ea-6862-47b0-a05b-180a46da6219
Commits

Reviewing files that changed from the base of the PR and between 9b9a36c and 9fc335b.

Files selected for processing: 2

  • crates/tinymemory-api/src/safety/mod_tests.rs
  • crates/tinymemory-api/src/safety/rules.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@tinysweeper

tinysweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Tiny Sweeper review

Reviewed head: 9fc335bf8b76ab75fb7e2cd82106251b0fa4c575

Verdict: Ready for maintainer review · Priority: none
Coverage: Reviewed 2 of 2 files.
Pull request purpose (title): fix(safety): detect…

Diagnostics and supporting details

Full summary

Pull request purpose (title): fix(safety): detect grouped IBANs and validate them with mod-97. Tiny Sweeper completed its review; deterministic results follow.

Review snapshot

Change surface Files Review signal Count
Production 1 Active findings 0
Tests 1 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.

Features

  • Modified — IBAN pattern rule accepts grouped and lower-case spellings: Grouped (space- or hyphen-separated) and lower-case IBANs, previously missed entirely, are now detected as BankAccount identifiers; the two spellings are separate alternatives so a contiguous value does not run on into the following word. (crates/tinymemory-api/src/safety/rules.rs fn build_rules() -> Vec<Rule> {)
  • Added — Mod-97 IBAN validator `is_iban`: Shape-matching candidates are now checksum-validated, so values like a one-digit-off IBAN or a random two-letters/two-digits/eleven-alphanumerics string no longer force High risk; the validator bounds length before slicing and folds the remainder incrementally. (crates/tinymemory-api/src/safety/rules.rs pub(crate) fn is_luhn_valid(raw: &str) -> bool {)

Tests

  • unit — Asserts grouped (space and hyphen), lower-case, and multi-country IBAN examples are detected as BankAccount at High risk.: Pins the new grouped/lower-case detection behavior introduced by the pattern change. (crates/tinymemory-api/src/safety/mod_tests.rs fn detects_iban_bank_account() {)
  • unit — Asserts IBANs with a bad checksum and random-shape alphanumeric values are not flagged as BankAccount.: Pins the validator's rejection behavior that the new `is_iban` introduces. (crates/tinymemory-api/src/safety/mod_tests.rs fn detects_iban_bank_account() {)
  • unit — Asserts `is_iban` accepts valid contiguous, grouped, and lower-case values and rejects a one-digit-off value, a digit in the country code, and a too-short value.: Directly exercises the new validator's length, character-class, and mod-97 checks. (crates/tinymemory-api/src/safety/mod_tests.rs fn luhn_validator_accepts_known_good_and_rejects_bad() {)

Findings

No active actionable findings.

Before merge

None.

Agent review details

critique

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The critique lane found no blocking defect: `is_iban` bounds length to 15–34 before slicing, filters only ASCII space and hyphen so byte lengths equal character counts, and the digit/letter fold reproduces the standard mod-97 computation.
  • Lane summary: The change replaces the validator-less contiguous IBAN rule with a mod-97-checked rule that also matches the grouped spelling and lower-case input, and moves it ahead of the card rule. `is_iban` is correct as written: it bounds the length to 15–34 before slicing `compact[..4]`, filters only ASCII space and hyphen so byte lengths equal character counts, and the digit/letter fold reproduces the standard mod-97 computation. The new tests match the rules they exercise and the assertions about High risk hold, since BankAccount is a strong identifier. I found no defect worth blocking on. _The code index is behind this pull request (indexed at `d4c734a30dc1`), so retrieved context may be out of date._

security

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The security lane found no concrete misbehaving input and no repository-rule violation; the validator bounds-checks before slicing, the regex alternatives are word-boundary anchored, and the rule ordering lets the longer identifier claim its span first.
  • Lane summary: The change adds an IBAN validator and a grouped/contiguous IBAN pattern rule, plus tests. The validator bounds-checks length before slicing, the regex alternatives are anchored with word boundaries, and the rule is ordered before the card rule so the longer identifier claims its span first. I found no concrete input on which the new code misbehaves and no repository-rule violation. _The code index is behind this pull request (indexed at `d4c734a30dc1`), so retrieved context may be out of date._

tests

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The tests lane found the new tests pin the behavior the diff introduces, covering grouped/lower-case detection, bad-checksum rejection, whole-value redaction, and the validator itself.
  • Lane summary: The change adds a real mod-97 IBAN validator to the safety rules and rewrites the IBAN pattern to accept grouped, hyphenated and lower-case spellings, with new tests covering grouped/lower-case detection, bad-checksum rejection, whole-value redaction, and the validator itself. Those tests pin the behaviour the diff introduces, so the change looks sound to merge. _The code index is behind this pull request (indexed at `d4c734a30dc1`), 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 `d4c734a30dc1`), so retrieved context may be out of date._

description

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The description lane found the description matches the diff, including the acknowledged greedy-repetition limit, with no defect in the code as written.
  • Lane summary: The change replaces the unvalidated IBAN pattern with a case-insensitive contiguous-or-grouped pattern backed by a mod-97 validator, moves the rule ahead of the card rule, and adds tests for detection, rejection and full-span redaction. The description matches the diff, including the acknowledged greedy-repetition limit, and I found no defect in the code as written. _The code index is behind this pull request (indexed at `d4c734a30dc1`), so retrieved context may be out of date._
Evidence and run details
  • Models: deepseek-v4.1-flash, ladder/vectors-oai3
  • Spend: $0.002939
  • Tokens: 201239 input · 4154 output · 57344 cached · 369 embedding
  • Updated: 2026-11-11T08:43:07Z
Head State Pass summary
f247ba6499e9 incomplete 0 active finding(s), 0 resolved finding(s) (at 2026-10-13T12:35:48Z)
9fc335bf8b76 ready for maintainer review 0 active finding(s), 0 resolved finding(s) (at 2026-11-11T08:43:07Z)

tinysweeper 0.1.2

@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, but could not review everything, so this is not an approval: crates/tinymemory-api/src/safety/mod_tests.rs, crates/tinymemory-api/src/safety/rules.rs.

             $0.0017 · 136,549 in / 22,106 out · 10,240 cached (7%) · ladder/vectors-oai3, deepseek-v4.1-flash · 369 embedded
critique:    $0.0007 · 49,130 in  / 7,874 out  · 2,048 cached (4%)  · deepseek-v4.1-flash
tests:       $0.0007 · 63,261 in  / 11,046 out · 4,096 cached (6%)  · deepseek-v4.1-flash
description: $0.0000 · 20,016 in  / 432 out    · 4,096 cached (20%) · deepseek-v4.1-flash

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

@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.0029

@M3gA-Mind
M3gA-Mind merged commit d4db765 into tinyhumansai:main Nov 11, 2026
23 of 24 checks passed
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.

Detect and redact ordinarily grouped IBAN identifiers

2 participants