← Back to Pull requests

Send Enable Banking a PSU IP only when it is a public address #4304

Closed
unknown closed this pull request without merging on Oct 20, 2026 21:04 UTC
View on GitHub
unknown unknown commented on Oct 18, 2026 19:32 UTC
Author

Closes #4296

Fork pre-flight: https://github.com/jaysbeekay/sure/pull/482 (same branch), where its CI and review history live. It merged at fe32b9a39; the two commits since (234010352, cf0454a11) answer the review here.

Problem

On a self-hosted instance reached over a LAN or VPN, last_psu_ip holds the browser's private address (Rails trusts private ranges as proxies, so request.remote_ip is the LAN address). EnableBankingItem#build_psu_headers forwarded it as Psu-Ip-Address to banks that require that header, and HypoVereinsbank rejects it with FORMAT_ERROR: PSU IP Address field not valid. Every balance and transaction fetch failed.

Change

build_psu_headers sends the header only when last_psu_ip is a public address. It leaves it out for:

  • private addresses (10/8, 172.16/12, 192.168/16, fc00::/7);

  • loopback and link-local addresses;

  • the unspecified address;

  • carrier-grade NAT, 100.64.0.0/10 (used by Tailscale), which IPAddr#private? does not cover;

  • IANA's other special-purpose ranges that aren't globally reachable: IETF protocol assignments, documentation, benchmarking (198.18.0.0/15, which a VPN can assign), multicast, reserved and broadcast, and their IPv6 counterparts;

  • an unparseable value.
  • An IPv6 address that carries an IPv4 one (IPv4-mapped, IPv4-compatible, NAT64, 6to4) is checked as that IPv4 address. Leaving the header out is what the reporter's workaround (NULLing last_psu_ip) already does, and HVB accepts it. Filtering where the header is built also fixes rows already stored, with no migration.

    The check is NetworkAddress.public?, in a new app/models/network_address.rb. Provider::Simplefin#embedded_ipv4 moved there unchanged, and SimpleFIN delegates to it, so the unwrapping is written once (review feedback). SimpleFIN's blocked-network lists stay its own: which hosts it may connect to depends on the app mode, which isn't the question here. SimpleFIN's tests for each IPv6 encoding pass unchanged.

    Blast radius: build_psu_headers has one caller, EnableBankingItem::Importer, which uses it for the balance, booked-transaction and pending-transaction fetches.

  • With a public IP the result is unchanged.

  • With a non-public one it is {}, the same value already sent when last_psu_ip is NULL.
  • Left alone: the other readers of last_psu_ip (with_stale_psu_ip, DataCleanerJob, revoke_session) only clear it. The two controller writes are unchanged.

    Validation

  • Fails first: "build_psu_headers leaves out a PSU IP that is not a public address" fails on upstream/main at its first case (192.168.1.20 is sent) and passes after. It covers private, Docker bridge, CGNAT, IPv4/IPv6 loopback, ULA, IPv4/IPv6 link-local, mapped CGNAT, unspecified and unparseable values, an address from each special-purpose range, and a private address written as NAT64, 6to4 and IPv4-compatible.

  • Regression guards:

  • - a public IPv4 and IPv6 address, and a public address written as NAT64, are still sent;
    - nothing is sent when the bank also requires a header Sure can't supply.
  • Mutation: each of the filter's 8 original conditions was removed in turn, and each was caught. After the review: removing any one of the 15 special-purpose ranges fails the test, and dropping the NAT64 or 6to4 unwrapping fails both this test and SimpleFIN's.

  • Fork gates: light and full Gatekeeper reviews on the first commit, both with no findings; fork CI green.

  • Suites:

  • - full suite: 12,302 runs, 0 failures, 36 skips, at cf0454a11;
    - RuboCop and Brakeman: clean;
    - no UI change, no migration, no new dependency.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

    Bug Fixes
    PSU IP addresses are now sent only when they are valid public IPv4 or IPv6 addresses. Private, reserved, special-purpose, or invalid addresses are omitted.
    PSU headers are omitted when required header information cannot be provided.
    Address handling now consistently recognizes IPv4 addresses embedded in supported IPv6 formats, improving validation accuracy.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 524 lines (+393 / -131) across 6 files Reviewer: jaysbeekay Review duration: 2971m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 524 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.375
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4304"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.8% (MEDIUM) · Higher = larger blast radius
    47.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.9% · Safe to merge
    18.9%