Skip to content

Accept configured gateway purposes in the relay - #2026

Merged
DanGould merged 4 commits into
payjoin:masterfrom
gf5901:mailroom-allowed-purposes
Nov 7, 2026
Merged

DanGould merged 4 commits into
payjoin:masterfrom
gf5901:mailroom-allowed-purposes

Conversation

@gf5901

@gf5901 gf5901 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2024.

Adds an [ohttp_relay] extra_allowed_purposes setting to payjoin-mailroom. The relay still forwards only to gateways that opt in through allowed_purposes. BIP77 is always accepted and the list is empty by default, so existing relays behave exactly as before. Operators who also want to relay another protocol's traffic can list its purposes.

Commits

  1. Rename Policy::bip77_allowed to opted_in. No behavior change.
  2. The setting itself:
    • AllowedPurposes in the prober: BIP77 plus the configured purposes, each 1 to 255 bytes;
    • checked at the start of each serve path, before anything else starts;
    • Service::new_with_purposes, used by all three serve paths (plain, ACME, and manual TLS);
    • docs in the README and config.example.toml, and a CHANGELOG line.

API notes

  • Service::new is unchanged.
  • New: ohttp_relay::{AllowedPurposes, InvalidPurpose}, Service::new_with_purposes, config::OhttpRelayConfig, and a Config::ohttp_relay field. Code that builds Config with a struct literal would need the new field; in-tree code uses Config::new and Default.
  • Service::new_with_roots, behind _manual-tls, now takes the purposes too, so the manual-TLS path honors the setting.

Testing

  • New unit tests:
    • a gateway that lists only another purpose is refused by default and reached once that purpose is configured;
    • BIP77 gateways are still reached;
    • bad lengths are rejected;
    • config parsing.
  • New end-to-end test (7009cb4, from codaMW's review): through serve_manual_tls, with extra_allowed_purposes set, a gateway that declares only that purpose receives the relayed request; without the setting, the relay returns 404.
  • Run locally for payjoin-mailroom:
    • cargo fmt --check;
    • cargo clippy --all-targets --all-features -- -D warnings;
    • the library tests with --all-features (93 pass);
    • cargo doc with -D warnings;
    • codespell.
  • Not run locally: the nginx integration test (--test integration), nix fmt, and the full ./contrib/test_local.sh, because I don't have nginx or nix set up. There are no dependency changes, so both lockfiles are untouched.
  • End to end: I ran this branch's mailroom in front of a local Lantern Zero server. With the purpose configured, a wallet's requests, including a 25 s long-poll, went through. A stock mailroom returned 404.

Reviewer: @DanGould, who discussed the approach on #2024.

AI disclosure: this change, its commit messages, and this description were written with an AI coding assistant (Claude Code). I completed the local AI review described in CONTRIBUTING.md. It found one issue, purposes being validated only after the directory had started, which is fixed. The text of #2024 and my comment there were also AI-drafted, and I should have said so then.

The prober's policy records whether a gateway opted in to being
reached through this relay. Today that means declaring the BIP77
purpose, but the next commit lets operators accept other purposes
too, so name the field for what it means rather than for BIP77.

No behavior change.
The relay forwards only to gateways that opt in by listing the BIP77
purpose in their allowed_purposes response. That keeps operators from
relaying traffic they didn't agree to, but it also means an operator
who is happy to relay another protocol's traffic has no way to do so.

Add an [ohttp_relay] extra_allowed_purposes setting. The prober now
treats a gateway as opted in if it lists BIP77 or any configured
purpose. BIP77 is always accepted and the list is empty by default, so
existing relays behave exactly as before. Each purpose must fit an
allowed_purposes entry (1 to 255 bytes); anything else is refused at
startup.

Service::new is unchanged. Service::new_with_purposes takes the set,
and all three serve paths (plain, ACME, and manual TLS) read it from
the config, so the setting can't be silently ignored on one of them.

Closes payjoin#2024.

@caarloshenriq caarloshenriq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No strong opinion on the concept, deferring to @DanGould on whether mailroom should relay for other protocols, since that’s a scope decision for the project. Code-wise this looks solid: defaults are unchanged, purposes are validated before startup on all three serve paths, and the new prober test fails if the check reverts to BIP77-only. Mailroom lib tests pass locally (the 3 failures are IPv6 binds in my environment, same on master).

One open question from #2024 that I don’t think got answered: the bootstrap CONNECT path goes through the same opt-in check, so extra purposes apply there too. Is that intended?

Left two small comments inline.

.with_list_parse_key("acme.contact")
.with_list_parse_key("access_control.blocked_regions")
.with_list_parse_key("access_control.blocked_ips")
.with_list_parse_key("ohttp_relay.extra_allowed_purposes")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: with comma-separated env parsing, a purpose containing a comma can only be set through the TOML file. Maybe worth a note in config.example.toml.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a note to config.example.toml in eab8c4c.

/// Resolves on SIGINT or SIGTERM, the signals a terminal and systemd use to
/// stop the service. Returning from the serve loop instead of dying in the
/// default handler gives the weekly buckets a chance to reach disk.
/// The gateway purposes the relay forwards to: BIP77 plus any configured.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This landed between lshutdown_signal’s doc comment and the function, so relay_purposes now carries the “Resolves on SIGINT or SIGTERM…” docs and shutdown_signal has none. Could you move it above that block?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, moved it above the doc comment in eab8c4c.

@gf5901

gf5901 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @caarloshenriq.

On CONNECT: yes, that's intended. Lantern Zero wallets fetch a gateway's key configuration through two relays and compare the copies, and through mailroom that fetch goes over the bootstrap tunnel, so the extra purposes need to apply there too. The tunnel and the POST path share one opt-in check, so the tunnel reaches only gateways that list a configured purpose. With extra_allowed_purposes left empty, it stays BIP77-only as today. If you'd rather keep the bootstrap BIP77-only, I can make it a separate setting.

Both inline comments are fixed in eab8c4c.

@caarloshenriq

Copy link
Copy Markdown
Contributor

Thanks for the changes @gf5901!

Small thing: your last commit (8ab03e2) has a Co-authored-by: Claude trailer. Per the AI disclosure section of AGENTS.md, the disclosure goes in the PR body rather than in commits, so could you drop it from the commit message?

Move relay_purposes above shutdown_signal's doc comment, which it had
taken over. Note in config.example.toml that a purpose containing a
comma can only be set in the TOML file, since the environment variable
is split on commas.
@gf5901
gf5901 force-pushed the mailroom-allowed-purposes branch from eab8c4c to 9a36272 Compare November 3, 2026 16:01
@gf5901

gf5901 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, @caarloshenriq. Done: I dropped the trailer and force-pushed. The commit is now 9a36272, with the same changes (the trailer was on eab8c4c, the commit before that). The AI disclosure stays in the PR body only.

@codaMW codaMW left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ran the full mailroom suite on 9a36272 (--all-features, all green) plus mutations. Logic checks out, and the opt-in gate is load-bearing (forcing any_of to true fails test_other_purposes_need_the_operator_to_opt_in).

One gap before a full ACK: nothing covers the config-to-relay path. I made relay_purposes return AllowedPurposes::default(), dropping the operator's configured purposes, and the whole suite still passed. A test that sets extra_allowed_purposes and checks a gateway declaring only that purpose is reached would close it.

Otherwise looks good. AI-assisted review, I ran the suite and mutations myself.

@coveralls

coveralls commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 42300982630

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.3%) to 87.844%

Details

  • Coverage increased (+0.3%) from the base build.
  • Patch coverage: 18 uncovered changes across 3 files (172 of 190 lines covered, 90.53%).
  • 341 coverage regressions across 6 files.

Uncovered Changes

File Changed Covered %
payjoin-mailroom/src/lib.rs 73 59 80.82%
payjoin-mailroom/src/ohttp_relay/gateway_prober.rs 92 89 96.74%
payjoin-mailroom/src/config.rs 9 8 88.89%
Total (4 files) 190 172 90.53%

Coverage Regressions

341 previously-covered lines in 6 files lost coverage.

File Lines Losing Coverage Coverage
payjoin-cli/src/app/v2/mod.rs 191 58.18%
payjoin/src/core/receive/v2/mod.rs 131 93.23%
payjoin-cli/src/app/wallet.rs 13 93.05%
payjoin/src/core/receive/v2/session.rs 3 99.08%
payjoin-mailroom/src/lib.rs 2 69.31%
payjoin-mailroom/src/config.rs 1 66.67%

Coverage Stats

Coverage Status
Relevant Lines: 18616
Covered Lines: 16353
Line Coverage: 87.84%
Coverage Strength: 313.78 hits per line

💛 - Coveralls

Serves mailroom with extra_allowed_purposes set and relays a request to a
mock gateway that declares only that purpose; without the setting the
gateway is not reached. Covers the config-to-relay path, which no test
exercised before.
@gf5901

gf5901 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the mutation run, @codaMW. Good catch on the gap.

Added in 7009cb4: configured_purposes_reach_the_relay in payjoin-mailroom/src/lib.rs. It serves mailroom through serve_manual_tls with extra_allowed_purposes set, and relays a POST to a mock gateway that declares only that purpose: the relay answers 200 and the request reaches the gateway. With the setting left empty, the same gateway isn't reached (404). With your mutation (relay_purposes returning AllowedPurposes::default()), the test now fails. The full mailroom suite passes with --all-features and with default features, and clippy is clean.

(AI-assisted: the test and this comment were written with Claude Code; I ran the mutation and the suite.)

@DanGould DanGould left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK 9a36272

Very happy to see this as it will let us experiment with some esplora proxying as well.

I ran some extra validation with bots:

I ran the PR and its base through the real mailroom relay and checked configured allowed purposes from both TOML and environment configuration. I verified exact gateway response forwarding; multiple, unrelated, and unconfigured purposes; invalid-purpose handling; and purpose length limits.

Default denial and BIP77 compatibility match the base, including 25-second delayed responses. I also checked CONNECT bootstrap over local HTTPS, with the configured purpose accepted and the default unconfigured case rejected.

And have some follow ups to share after

I added a separate generic config-to-relay regression test using a synthetic purpose. It passes end to end and returns 404 when I mutate the relay to discard the configured purposes. I’ll point to the test-timing hardening issue separately

@DanGould DanGould left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK 9a36272

@DanGould
DanGould merged commit 0065ad2 into payjoin:master Nov 7, 2026
16 checks passed
@DanGould DanGould mentioned this pull request Nov 7, 2026
3 tasks done
@gf5901

gf5901 commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for merging this, @DanGould, and to @caarloshenriq and @codaMW for the reviews.

I tested master (0065ad2) in front of a Lantern Zero server. With the purpose configured, the whole wallet flow works, including 25 s long-polls. The key configuration comes through the CONNECT bootstrap tunnel, and it matches a direct fetch byte for byte. Without the setting, every request is refused, as before.

Once it's in a mailroom release: would you consider adding Lantern Zero's purpose to the payjo.in relay?

[ohttp_relay]
extra_allowed_purposes = ["LanternZero v0 4bca76ac-1094-4330-97df-03d5c81b576d"]

Lantern Zero is a notification service for Zcash wallets. Wallets reach their server through two independent OHTTP relays, so neither the relay nor the server sees both who's asking and what. Right now servers under lanternzero.com have only one relay that isn't ours, and payjo.in would be a good second. The traffic is small: every request and response is padded to 4 KiB, and wallets hold long-polls of 25–30 s.

If you're open to it, we'd list the relay in our spec's relay list (https://github.com/principlezerolabs/lanternzero/blob/main/spec/relays.md) with your contact and log retention, through a PR you can review. Wallet vendors choose which listed relays they use; we don't assign them.

@DanGould

DanGould commented Nov 8, 2026

Copy link
Copy Markdown
Member

would you consider adding Lantern Zero's purpose to the payjo.in relay?

Glad this can be useful to you and your users. Our relay is winding down before 12/31 because we've moved to a model where we list mailrooms that adhere to a certain staindard at https://payjoin.org/mailroom rather than one one ourselves, so we're not a good fit for a host.

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.

payjoin-mailroom: let relay operators accept OHTTP gateway purposes other than BIP77

5 participants