Live Nov 18 · Cohort 3Nov 18, 19:00 MSK — free hands-on AI agents live workshop · Live Cohort 3 starts Nov 23Join Nov 18 Live →Cohort 3 (Nov 23)
ReleaseInsight · On RadarHabr AI→ original

ZuBrIQ gateway hides cards and UNPs from GPT and Claude, swapping in lookalike doubles even when streaming

A bank wants to use GPT and Claude but cannot send them a customer's card number or UNP, the tax ID of a company in Belarus. The ZuBrIQ gateway replaces them with plausible doubles that have valid checksums, then restores the originals in the response. When text arrives in chunks in a stream, the gateway holds back the tail of the buffer so it doesn't lose a number split across two chunks. The takeaway: it is easier to keep this protection in one gateway than in every application.

AI-processed from Habr AI; edited by Hamidun News
ZuBrIQ gateway hides cards and UNPs from GPT and Claude, swapping in lookalike doubles even when streaming
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Key metric #1Doubles are stored in Redis for one hour; the same UNP always maps to the same replacement
Key metric #2If Redis or the detector goes down, the request is rejected rather than sent to the model
Key metric #3The gateway does not cover addresses, e-mail or free text: you need Presidio

Picture a bank accountant pasting a contract into a chat with GPT or Claude. The contract contains a customer's card number, a UNP (the payer account number, a company's tax identifier in Belarus) and the director's full name. All of this is personal data, and it travels with the request to an external model abroad.

This is why banks often refuse to let large language models (LLMs) into their workflows at all. The team behind the Belarusian gateway ZuBrIQ described on Habr how it closed this risk: the model receives not the real numbers but plausible doubles, and the gateway swaps them back in the response. It also works in streaming mode, when the model returns its answer in chunks.

This is the authors' own description and the article contains no independent measurements, but there are enough engineering decisions in it to be worth examining.

Why doubles instead of a [CARD] tag

The simplest way to hide data is to replace a number with a tag such as [CARD]. But the model cannot tell two identical [CARD] tags apart. It won't understand that the cards are different, won't reconcile amounts and won't draw up a payment order.

So the gateway substitutes data of the same type and format. Instead of the UNP 192628898, the model sees a different UNP with a valid check digit. Instead of a card, it gets a number that passes the Luhn algorithm check. Instead of an IBAN, it gets a value with a correct mod-97 check. Instead of "Иванов Иван" it receives "Егоров Игорь". To the model, this is an ordinary document.

The "original ↔ double" pairs sit in Redis for one hour. The same UNP for the same user always turns into the same replacement, so the model understands that three messages are about one counterparty. Restoration is tied to the user: the gateway will not reveal another user's double in a response.

Technically, this is a plugin for LiteLLM: a CustomLogger class with three hooks, for input, for a regular response and for a streamed one. It plugs in with a single line in the proxy config.

How to avoid masking too much and losing a number in a stream

A naive "9 digits" regex will catch anything: a UNP, a BIK, an order number. So every match goes through validation. For a UNP, the gateway computes a weighted check digit. For cards, it runs the Luhn algorithm and checks the issuing bank's prefix (BIN). For a Russian INN, it uses the Federal Tax Service algorithm, and for an IBAN, mod-97. But even a checksum is not enough: a random nine-digit number passes the UNP check in about one case in ten. So the gateway also looks for the words "УНП" or "БИК" near the number.

If detectors overlap (a 20-digit account number contains a 16-digit "card" inside it), the more specific type wins: IBAN, then account number, BIK, card, INN, passport, full name. In a tie, the longer match wins. A number with a checksum error, for example from a typo, is left alone entirely, so the gateway doesn't "fix" real data and the model doesn't answer about a different number.

The trickiest part is streaming. The model returns text in chunks, and the number 732432413 may arrive as "7324" in one chunk and "32413" in the next. If each chunk is replaced separately, the double is never found and the client sees someone else's digits.

The authors hold back the tail of the buffer if it looks like the beginning of any of that user's doubles: a tail of "73" waits for its continuation. If there is no match, the text goes out immediately. According to the description, the delay is one or two chunks, and only when the response contains something resembling the user's data.

Whatever remains at the end of the stream goes out as a final chunk.

Where they went wrong and what is left uncovered

Full names have no checksums, so names are found by context: "Уважаемый" (Dear), "господин" (Mr.), "клиент" (client). The authors candidly described two mistakes. First, the detector did not know corporate roles, so the phrase "директор Иванов Пётр Сергеевич" (director Ivanov Pyotr Sergeevich) went to the model in plain text. They expanded the list (director, accountant, founder, sole proprietor, power of attorney) and added a test with 11 such phrasings. All 11 failed on the old detector. Then it turned out that the generator could produce a double with the same surname: instead of "Козлов Андрей Павлович" the model received "Козлов Игорь Сергеевич", so the real surname still leaked. Now the generator re-rolls any word that matches the original.

The authors' conclusion: for legally significant scenarios, it is better to cover names with an entity list rather than with heuristics alone.

By default the gateway runs in fail-closed mode: if Redis goes down or the detector breaks, the request is rejected. Every detection is logged as JSON with the types and number of items found, but without the data itself, and then forwarded to a SIEM. For addresses, e-mail and dates, you can enable Microsoft Presidio as a second layer, strictly after the main one, so that it sees the doubles already.

The limitations are stated plainly: the layer does not cover UNPs containing letters, addresses, or phrases like "my neighbor from the third floor", and images and files are not processed.

What to do in practice

Separately, the authors remind readers of the risk posed by the gateway itself. On 21 October 2026, for about two hours, a compromised LiteLLM 1.107.0 sat in PyPI and Docker images with an infostealer that stole proxy keys. The team had specified the dependency as a version range. The version is now pinned, and the image is mirrored to the team's own registry.

For anyone building corporate access to LLMs, this yields a short list. Do masking in one place at the entry point, not in every application. Replace data with plausible values rather than tags. Test streaming separately, and make a protection failure block the request instead of letting it through. Pin the versions of components through which all secrets pass.

Story

Key Questions Answered

Why doubles instead of a [CARD] tag?

The simplest way to hide data is to replace a number with a tag such as [CARD]. But the model cannot tell two identical [CARD] tags apart. It won't understand that the cards are different, won't reconcile amounts and won't draw up a payment order. So the gateway substitutes data of the same type and format. Instead of the UNP 192628898, the model sees a different UNP with a valid check digit. Instead of a card, it gets a number that passes the Luhn algorithm check.

How to avoid masking too much and losing a number in a stream?

A naive "9 digits" regex will catch anything: a UNP, a BIK, an order number. So every match goes through validation. For a UNP, the gateway computes a weighted check digit. For cards, it runs the Luhn algorithm and checks the issuing bank's prefix (BIN). For a Russian INN, it uses the Federal Tax Service algorithm, and for an IBAN, mod-97. But even a checksum is not enough: a random nine-digit number passes the UNP check in about one case in ten.

Where they went wrong and what is left uncovered?

Full names have no checksums, so names are found by context: "Уважаемый" (Dear), "господин" (Mr.), "клиент" (client). The authors candidly described two mistakes. First, the detector did not know corporate roles, so the phrase "директор Иванов Пётр Сергеевич" (director Ivanov Pyotr Sergeevich) went to the model in plain text. They expanded the list (director, accountant, founder, sole proprietor, power of attorney) and added a test with 11 such phrasings. All 11 failed on the old detector.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Unified AI Workspace · Nomad

Test Frontier LLMs & Autonomous Agents in One Workspace

Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.

Try Nomad AI →Launch Nomad Agent
What do you think?
Loading comments…