Skip to content

Scope Avenia Pix key lookups to the user's sub-account and keep Pix keys out of logs - #1477

Merged
ebma merged 5 commits into
stagingfrom
fix/pix-key-check-limits
Nov 23, 2026
Merged

ebma merged 5 commits into
stagingfrom
fix/pix-key-check-limits

Conversation

@ebma

@ebma ebma commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Changes to how the API asks Avenia to resolve Pix keys (GET /v2/account/bank-accounts/brl/pix-info):

  • Encode the key in the Avenia query (fix(shared)): BrlaApiService.validatePixKey was the only method in the client that put a caller's value into an Avenia query string without encodeURIComponent. Characters such as the leading + of a phone key now reach Avenia as typed.
  • Resolve offramp Pix keys under the user's sub-account (feat(shared), fix(api)):
    • Avenia charges each DICT lookup to the sub-account named in subAccountId, and to the main account when none is given. Each account and sub-account has its own token bucket (Avenia integration guide, "Bank Accounts → DICT lookup limits").
    • validatePixKey takes an optional subAccountId. The offramp recipient check (validateAveniaOfframpRecipient) passes the user's sub-account, which it already resolves, so each registration draws on that user's own quota.
    • Checked against Avenia production: a lookup with subAccountId is accepted and charged to that sub-account's bucket, independently of the main account's.
    • The anonymous pre-flight GET /v1/brl/validatePixKey is unchanged and still uses the main account.
  • Report lookup outages as provider failures, not bad keys (fix(api)):
    • The recipient check answered 400 "Invalid pixKey or receiverTaxId." for every failed lookup, so a valid key was reported as invalid during a provider outage. Only Avenia's 400 is about the key.
    • A quota limit (429) now answers 502 "The payment provider is temporarily unavailable. Please try again shortly.". Other provider errors reach mapProviderFailure in the ramp controller unchanged: 502 for a 5xx or a timeout, 422 for another 4xx.
  • Keep Pix keys and tax IDs out of logs (fix(api)):
    • The recipient check logged the Pix key when Avenia's lookup failed, and the receiver's full tax ID when it wasn't comparable or didn't match. The unhandled-payment worker logged a tax ID on error. docs/security-spec/07-operations/client-observability.md §4 forbids both.
    • The warnings now name only the failed check, and the worker names the affected ramp IDs.

The security spec (05-integrations/brla.md, invariant 16) now records the sub-account-scoped lookup.

An earlier revision of this PR also added a per-IP limit on the pre-flight route. It was dropped, and the branch history rewritten without it, in favour of scoping the registration lookup. App traffic reaches the API through shared proxy addresses, so a per-IP limit would have pooled unrelated users.

Compatibility

  • One deliberate status change on POST /v1/ramp/register: a Pix lookup that fails for a reason other than the key now answers 502 or 422 with the existing provider-failure messages, where it used to answer 400 "Invalid pixKey or receiverTaxId.". A bad key or an owner mismatch still answers that 400. The SDK throws a VortexSdkError with that status, and the Stocks app already translates both messages.
  • No other route, request, response body or status code changes.
  • BrlaApiService.validatePixKey(pixKey, subAccountId?) gains an optional parameter, so existing callers are unaffected. The SDK doesn't use this class.
  • Wire-contract snapshot unchanged.

Testing

  • brlaApiService.test.ts:
    • Phone and email keys are sent encoded.
    • The given sub-account is appended as its own parameter, and a key containing &subAccountId= and # can't override it.
    • Both cases fail without the change.
  • avenia-registration.test.ts:
    • The lookup runs as (pixKey, "subaccount-1").
    • All three recipient rejections (lookup failure, a CNPJ against a masked CPF, a mismatch) log nothing containing the Pix key or either tax ID.
    • Both fail without the change.
    • A 400 from Avenia is still a bad key, a 429 becomes the 502, and 0, 404 and 503 reach the caller unchanged. Fails without the change.
  • Full API suite with coverage, the shared suite, Biome, API and shared typechecks, and wire-contract:check all pass.

Every other value this client puts into an Avenia query string is
encoded; the Pix key was not, so characters such as the leading `+`
of a phone key did not reach Avenia as typed.
@netlify

netlify Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vortexfi canceled.

Name Link
🔨 Latest commit 86714b5
🔍 Latest deploy log https://app.netlify.com/projects/vortexfi/deploys/6b04633cd392874035e21fdb

@netlify

netlify Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vortex-sandbox ready!

Name Link
🔨 Latest commit 86714b5
🔍 Latest deploy log https://app.netlify.com/projects/vortex-sandbox/deploys/6b04633cec5b63254f5dc2f0
😎 Deploy Preview https://deploy-preview-1477--vortex-sandbox.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vrtx-dashboard canceled.

Name Link
🔨 Latest commit 86714b5
🔍 Latest deploy log https://app.netlify.com/projects/vrtx-dashboard/deploys/6b04633c9c5134f7af1c8be7

@ebma ebma changed the title Encode Pix keys sent to Avenia and rate-limit the Pix key check Encode and rate-limit Pix key checks; keep Pix keys and tax IDs out of logs Nov 23, 2026
ebma added 3 commits November 23, 2026 10:38
The offramp recipient check logged the Pix key when Avenia's lookup
failed and the receiver's full tax ID on a mismatch, and the
unhandled-payment worker logged a tax ID on error. The observability
spec forbids both. The warnings now name only the failed check, and
the worker names the affected ramp IDs.
Avenia charges each pix-info DICT lookup to the sub-account named by
subAccountId, or to the main account when none is given. The optional
parameter lets callers that act for a user charge that user's quota.
The offramp recipient check looked Pix keys up on Vortex's main Avenia
account, so every registration shared one DICT quota with every other
main-account lookup. It now passes the user's subAccountId, which the
check already resolves, so each user's lookups draw on their own
sub-account's quota.
@ebma
ebma force-pushed the fix/pix-key-check-limits branch from 0313909 to 160cb83 Compare November 23, 2026 09:49
@ebma ebma changed the title Encode and rate-limit Pix key checks; keep Pix keys and tax IDs out of logs Scope Avenia Pix key lookups to the user's sub-account and keep Pix keys out of logs Nov 23, 2026
validateAveniaOfframpRecipient turned every failed lookup into "Invalid
pixKey or receiverTaxId.", so a valid key was reported as invalid during
a provider outage. Only Avenia's 400 is about the key. A quota limit now
returns the temporary provider failure (502), and other provider errors
reach the register route's existing provider-failure mapping.
@ebma
ebma merged commit 6fc3889 into staging Nov 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant