paivana

HTTP paywall reverse proxy
Log | Files | Refs | Submodules | README | LICENSE

README (27745B)


      1 Paivana
      2 =======
      3 
      4 Paivana is an HTTP reverse proxy that gates access to a target website
      5 behind a GNU Taler payment.  Unpaid visitors receive a paywall page
      6 where they can pay using a GNU Taler wallet; once payment is confirmed
      7 the request is forwarded transparently to the configured upstream
      8 server.
      9 
     10 The sole binary is `paivana-httpd`.
     11 
     12 
     13 How it works
     14 ------------
     15 
     16 0. `paivana-httpd` learns prices from the Paivana templates configured
     17    in the taler-merchant-backend.  Paivana templates include a regular
     18    expression which determines the set of pages the template applies to.
     19    That expression (POSIX extended) is matched against the *entire*
     20    URL and is anchored at both ends, so `/premium/` applies to nothing
     21    while `.*/premium/.*` applies to every URL containing it.
     22 1. An HTTP client accesses a page at `paivana-httpd`.
     23 2. If the paywall is enabled for the respective URL and no valid access
     24    cookie is present, `paivana-httpd` redirects the browser to
     25    a static paywall HTML page (customizable Mustache template)
     26    referencing the payment template.
     27    The page includes a "Paivana" HTTP header to also facilitate agentic
     28    payments.
     29 3. The browser computes a unique payment identifier and
     30    renders a dynamic payment request (taler:// QR code
     31    or link) and long-polls the taler-merchant-backend awaiting
     32    completion of the payment.
     33 4. The user instructs their Taler wallet to complete the payment.
     34 5. The browser notices that the payment is complete and calls back to
     35    `POST /.well-known/paivana` (provided by `paivana-httpd`)
     36    with a reference to the unique payment identifier.
     37 6. `paivana-httpd` verifies the payment with the merchant, sets
     38    an access cookie, and redirects the browser to the original URL.
     39    The `expiration` bound into the payment identifier is the minimum
     40    acceptable cookie expiry. The proxy issues the cookie through the paid
     41    order's `max_pickup_time`, which can be later than that minimum.
     42 7. Requests with a valid cookie are forwarded to the upstream server
     43    via libcurl.  Both directions are streamed: bytes are passed on as
     44    they arrive, so the size of a proxied body is not bounded by memory
     45    (see "Architecture notes").
     46 
     47 The cookie carries a keyed hash over `(expiration time, website, client
     48 address)` keyed by a `paivana_secret` derived from the configured
     49 `SECRET`.  The construction is `GNUNET_CRYPTO_hkdf_gnunet()`, which is
     50 HMAC-based but is not itself an HMAC.  `SECRET` is required whenever the
     51 paywall is on. Keeping it stable across restarts preserves the validity
     52 of cookies already issued.  Under `-n` no cookie is ever minted
     53 and none is needed.
     54 
     55 Keep the same `SECRET` on every `paivana-httpd` serving one site — a
     56 cookie issued by one has to verify on the next — and treat it as
     57 equivalent to the content itself: whoever holds it can mint access for
     58 any visitor, URL and expiry.
     59 
     60 
     61 Dependencies
     62 ------------
     63 
     64 - GNUnet (libgnunetutil, libgnunetjson, libgnunetcurl)
     65 - libmicrohttpd
     66 - libcurl >= 7.62.0
     67 - libjansson
     68 - libgcrypt
     69 - GNU Taler: libtalerutil, libtalerjson, libtalermerchant,
     70              libtalermhd, libtalertemplating
     71 
     72 That is what the binary links against; `readelf -d` on it is the
     73 authority.  Paivana does not use libtalerexchange, and compresses
     74 nothing itself — that happens inside libtalermhd, which brings zlib
     75 with it.
     76 
     77 
     78 Build
     79 -----
     80 
     81 The project uses Meson but supports a GNU build process.
     82 
     83     ./bootstrap
     84     ./configure --prefix=$TARGET
     85     make
     86     sudo make install
     87 
     88 
     89 Configuration
     90 -------------
     91 
     92 Paivana reads an INI-style `.conf` file.  The only section used is
     93 `[paivana]`.  A minimal working configuration:
     94 
     95     [paivana]
     96     DESTINATION_BASE_URL = https://example.com/
     97     MERCHANT_BACKEND_URL  = https://backend.demo.taler.net/instances/sandbox/
     98     # Optional server-side route; useful with MERCHANT_BACKEND_UNIX_PATH.
     99     # MERCHANT_BACKEND_INTERNAL_URL = http://backend.internal/instances/sandbox/
    100     MERCHANT_ACCESS_TOKEN = secret-token:sandbox
    101     BASE_URL = http://localhost:9967/
    102     SERVE = tcp
    103     PORT  = 9967
    104 
    105 ### Required keys
    106 
    107   Key                     Description
    108   ----------------------  -----------------------------------------------------
    109   DESTINATION_BASE_URL    Upstream server to proxy to once payment is confirmed.
    110   MERCHANT_BACKEND_URL    Public base URL of the Taler merchant backend.
    111                           It is advertised to browsers and wallets as well
    112                           as used for backend requests unless an internal
    113                           URL is configured below.
    114   MERCHANT_ACCESS_TOKEN   Bearer token for all calls to the merchant backend.
    115   BASE_URL                Public base URL of Paivana.  Required unless `-f`
    116                           is given, in which case it is derived from the
    117                           forwarding headers (see below).
    118   SECRET                  Key for the access-cookie MAC.  Required unless
    119                           `-n`; see above for why there is no sensible
    120                           default.  It is *not* an input to the Paivana ID,
    121                           which the browser has to be able to recompute on
    122                           its own.  The Debian package generates one into
    123                           /etc/paivana/secrets/paivana.secret.conf, which
    124                           is not world-readable.
    125   SERVE                   `tcp`, `unix` (Unix-domain socket) or `systemd`
    126                           (socket activation).  There is no default: an
    127                           instance without it exits at startup, and it does
    128                           so only after the templates have been fetched.
    129   PORT                    TCP port.  Required when SERVE = tcp.
    130   UNIXPATH                Path to bind to.  Required when SERVE = unix.
    131   UNIXPATH_MODE           Access mode of that socket, octal.  Required
    132                           when SERVE = unix — it is what governs who may
    133                           reach Paivana, since a Unix-domain peer is
    134                           trusted to report the client address.
    135 
    136 ### Optional keys
    137 
    138   Key       Description
    139   --------  ---------------------------------------------------------------
    140   WHITELIST POSIX extended regular expression; matching request paths
    141             are forwarded without payment.  Matched against the
    142             *entire* path and anchored at both ends, so `/free/`
    143             whitelists nothing while `/free/.*` whitelists that
    144             subtree.
    145   TRUSTED_PROXIES
    146             IPv4 networks whose members are reverse proxies trusted to
    147             report the client address in `Forwarded` or
    148             `X-Forwarded-For`.  Only consulted with `-f`, and only
    149             needed when more than one proxy is in front.  See "Trusted
    150             proxies" below.
    151   TRUSTED_PROXIES6
    152             IPv6 counterpart of TRUSTED_PROXIES.
    153   CONNECTION_LIMIT
    154             Total number of concurrent client connections to accept,
    155             default 384.  Divided evenly over the listen sockets that
    156             come up, so the process-wide total is what you set --
    157             with no BIND_TO there are two (IPv4 and IPv6).  The current
    158             event loop uses select() and can represent only 1024 file
    159             descriptors.  Each active request may hold a client and an
    160             outbound socket, so the maximum is (1024 - 256 reserve) / 2
    161             = 384.  The reserve covers listeners, curl pools, resolver,
    162             scheduler and transient overlap.  Paivana refuses unsafe
    163             values or an RLIMIT_NOFILE below the calculated requirement.
    164   PAYMENT_CONNECTION_LIMIT
    165             Slots reserved within CONNECTION_LIMIT for payment-redemption
    166             POSTs, default 32.  This leaves 352 ordinary slots and also
    167             bounds the merchant lookups that unauthenticated clients can
    168             hold for their five-second long poll.  Must be at least 1 and
    169             smaller than CONNECTION_LIMIT.
    170   PER_IP_CONNECTION_LIMIT
    171             Concurrent connections accepted from any one client
    172             address, default 32; 0 disables the check.  Set it to 0
    173             wherever the peer address is not the client's -- under
    174             SERVE = unix or systemd every client shares one peer
    175             address, and behind a reverse proxy or a NAT many clients
    176             do, so a limit there throttles everyone at once.
    177   RELAY_MEMORY_LIMIT
    178             Aggregate accounting ceiling for ordinary-request streaming
    179             rings, default 268435456 bytes (256 MiB).  Startup requires
    180             (REQUEST_BUFFER_MAX + RESPONSE_BUFFER_MAX) multiplied by
    181             (CONNECTION_LIMIT - PAYMENT_CONNECTION_LIMIT) to fit.  The
    182             defaults account for 176 MiB and retain 80 MiB of this budget
    183             for configuration growth; templates, curl and allocator memory
    184             remain outside the accounting, which is why the margin matters.
    185   SHUTDOWN_GRACE_PERIOD
    186             Time accepted requests may finish after SIGTERM, default 60 s;
    187             0 means immediate shutdown.  Listeners are quiesced first, so
    188             socket activation queues new connections for the replacement.
    189             Keep the service manager's stop timeout above this value; the
    190             package uses 75 s to leave 15 s for cancellation and cleanup.
    191   BIND_TO   IP address to bind to; dual-stack wildcard if absent.
    192   DESTINATION_UNIXPATH
    193             Unix-domain socket to reach the upstream on instead of
    194             connecting to the authority in `DESTINATION_BASE_URL`.  That
    195             URL is still what the request line and `Host` are built
    196             from, so it remains required.
    197   MERCHANT_BACKEND_UNIX_PATH
    198             Unix-domain socket to reach the merchant backend.  The URL
    199             scheme of `MERCHANT_BACKEND_INTERNAL_URL` (or, when absent,
    200             `MERCHANT_BACKEND_URL`) is still spoken over that socket:
    201             use `http` for a cleartext socket and `https` only for a
    202             TLS-speaking socket.  An unusable path is a warning and the
    203             setting is then ignored, not a startup failure.
    204   MERCHANT_BACKEND_INTERNAL_URL
    205             Complete merchant-instance base URL used only for Paivana's
    206             server-side template and order requests.  It must be an HTTP(S)
    207             URL ending in `/` and include the instance path.  Defaults to
    208             `MERCHANT_BACKEND_URL`.  Set this to an `http` URL together with
    209             `MERCHANT_BACKEND_UNIX_PATH` when a public HTTPS merchant is
    210             exposed locally through a cleartext socket; browser-facing
    211             pay-template URIs, JavaScript and CSP continue to use the public
    212             `MERCHANT_BACKEND_URL`.
    213 
    214 
    215 Running
    216 -------
    217 
    218 $ paivana-httpd -c /etc/paivana/paivana.conf
    219 
    220 Besides the options GNUnet gives every program (`-c` / `--config`,
    221 `-L` / `--log`, `-l` / `--logfile`, `-h`, `-v`), Paivana takes four:
    222 
    223   -n, --no-payment    Bypass the paywall entirely — a pure reverse proxy,
    224                       which is what the test suite runs.  No cookie is
    225                       ever minted and `SECRET` is not required.
    226   -g, --global-payment
    227                       One payment grants access to the whole site rather
    228                       than to the URL it was made for.  The website goes
    229                       into the cookie's keyed hash as the empty string,
    230                       and the cookie is scoped to `/` rather than to the
    231                       page, so cookies minted under one setting do not
    232                       verify under the other: flipping it invalidates
    233                       whatever access is outstanding.
    234   -f, --respect-forwarded-headers
    235                       Take the client address from the forwarding
    236                       headers.  Only safe behind a proxy that overwrites
    237                       them; see "Deployment behind a reverse proxy".
    238   -u, --max-upload BYTES
    239                       Bytes of a request body held in memory at once
    240                       while relaying it upstream, default 262144.  A
    241                       throughput knob, not a limit: the largest body
    242                       accepted is MAX_REQUEST_SIZE.  For configurations
    243                       written when these were one number, setting this
    244                       and not MAX_REQUEST_SIZE still sets both.
    245 
    246 The daemon does not serve requests until it has fetched paywall templates
    247 from the merchant backend.  If template loading fails, startup is aborted:
    248 a template that could not be loaded would otherwise leave everything it
    249 covers unpaywalled.  Transient backend outages are the service manager's
    250 job to ride out -- the shipped `paivana-httpd.service` restarts with an
    251 increasing back-off, and does not restart on a configuration error.
    252 
    253 An order-status request that fails before receiving any HTTP response is
    254 retried once inside the original five-second deadline.  If that retry also
    255 fails early, Paivana's sampled warning is followed by one diagnostic GET for
    256 the same order with a forced fresh connection.  Its log record reports whether
    257 an HTTP status was completed or merely observed before a transfer error, the
    258 new-connection count, local and remote addresses, OS errno, HTTP version and
    259 DNS/TCP/TLS/first-byte/total timings.  The diagnostic uses the existing
    260 authenticated merchant context but never logs its bearer token or response
    261 body, and its result does not change the error returned to the client.  A real
    262 HTTP status from the forced-fresh request, after both shared-context attempts
    263 failed, is strong evidence for a connection-pool/reuse problem rather than a
    264 merchant application outage.
    265 
    266 An instance that offers no template at all is refused for the same
    267 reason: with nothing to sell, no URL ever matches a paywall and the
    268 entire site would be served for free without a word of warning.  Serving
    269 a site without a paywall is what `-n` is for, and it has to be asked for.
    270 
    271 
    272 Deployment behind a reverse proxy
    273 ----------------------------------
    274 
    275 The recommended production setup runs Paivana over a Unix socket and
    276 places nginx or Apache in front for TLS termination.
    277 
    278 In that setup Paivana **must** be started with `-f` /
    279 `--respect-forwarded-headers`.  A Unix-domain peer has no address of
    280 its own, so without `-f` there is no client address at all: the access
    281 cookie cannot be bound to a client, and `POST /.well-known/paivana`
    282 fails.  `-f` makes Paivana take the client address from the forwarding
    283 headers instead, and forward the chain it was given to the upstream
    284 rather than replacing it.
    285 
    286 Paivana reads both the RFC 7239 `Forwarded` header and the de-facto
    287 `X-Forwarded-*` ones, preferring `Forwarded` where both are present,
    288 and emits both upstream — the standardized one for origins that speak
    289 it, the de-facto ones for the many that do not.  Of the `X-Forwarded-*`
    290 family it emits `-For`, `-Proto`, `-Host` and `-Port`; the port is
    291 taken from the front end's `X-Forwarded-Port` under `-f`, and otherwise
    292 from the authority in `Host` when that names one.
    293 
    294 What the origin sees as `Host` is **not** what the client sent: it is
    295 the authority of `DESTINATION_BASE_URL`, because that is the name
    296 Paivana connects to.  The client's own value survives as
    297 `X-Forwarded-Host` (and as the `host` parameter of `Forwarded`).  An
    298 origin doing virtual hosting must therefore be configured for the
    299 `DESTINATION_BASE_URL` authority, and an origin that generates absolute
    300 URLs should be told to build them from `X-Forwarded-Host` /
    301 `X-Forwarded-Proto` / `X-Forwarded-Port`.  If it builds them from
    302 `Host` instead, its `Location` values will name Paivana's view of the
    303 origin — an internal host and port, which Paivana relays unchanged.
    304 That leaks the internal name, and points the client straight at the
    305 origin wherever the client can route to it, bypassing the paywall.
    306 
    307 `-f` is only safe if the server in front **writes** the forwarding
    308 headers itself, whether by overwriting them or by appending its own
    309 element.  What it must not do is pass the client's copies through
    310 untouched: Paivana believes the rightmost element (see "Trusted
    311 proxies"), so a header no hop of yours has written is a header the
    312 client filled in, and the client then chooses the identity its access
    313 cookie is bound to.  The configurations below get this right; if you
    314 write your own, note that nginx sets `X-Forwarded-For` only when told
    315 to and forwards a client-supplied `Forwarded` verbatim — and
    316 `Forwarded` is the one Paivana prefers.
    317 
    318 Conversely, do not pass `-f` to a Paivana that clients can reach
    319 directly — there it is the client, not a proxy, that is setting those
    320 headers.
    321 
    322 nginx (`/etc/nginx/sites-available/paivana`):
    323 
    324 An optional per-client concurrency limit belongs here rather than in
    325 Paivana when a Unix socket is used.  The shipped example contains commented
    326 `limit_conn_zone` / `limit_conn` directives.  Its value is a site policy,
    327 not part of Paivana's descriptor calculation: a low value also combines all
    328 legitimate users behind the same NAT, and nginx behind another proxy must
    329 first be configured to trust and recover the real client address.
    330 
    331     server {
    332         listen 443 ssl;
    333         server_name example.com;
    334 
    335         location / {
    336             proxy_pass http://unix:/run/paivana/httpd/paivana-http.sock;
    337             proxy_set_header Host $host;
    338 
    339             # $remote_addr, not $proxy_add_x_forwarded_for: this is
    340             # the outermost hop, so these overwrite rather than
    341             # extend what the client claimed.
    342             proxy_set_header X-Forwarded-For   $remote_addr;
    343             proxy_set_header X-Forwarded-Proto $scheme;
    344             proxy_set_header X-Forwarded-Host  $host;
    345             proxy_set_header X-Forwarded-Port  $server_port;
    346 
    347             # RFC 7239; preferred by Paivana over the above.  The
    348             # element is built by a `map` — see the shipped config.
    349             proxy_set_header Forwarded \
    350                 "$paivana_forwarded_elem;proto=$scheme;host=$host";
    351         }
    352     }
    353 
    354 Apache (requires mod_proxy, mod_proxy_http and mod_headers):
    355 
    356     <Location "/">
    357         # mod_proxy appends the real client to any X-Forwarded-For the
    358         # client itself sent, so drop the client's copies first.
    359         RequestHeader unset X-Forwarded-For
    360         RequestHeader unset X-Forwarded-Proto
    361         RequestHeader unset X-Forwarded-Host
    362         RequestHeader unset X-Forwarded-Port
    363         RequestHeader unset Forwarded
    364 
    365         # RFC 7239; Apache emits none of its own.  It has to be an
    366         # expr= value: %{...}e reads the CGI environment, which is not
    367         # populated when mod_headers runs, so the %{REMOTE_ADDR}e form
    368         # yields the literal string "(null)".
    369         RequestHeader set Forwarded \
    370             "expr=for=%{REMOTE_ADDR};proto=%{REQUEST_SCHEME};host=%{HTTP_HOST}"
    371 
    372         ProxyPass "unix:/run/paivana/httpd/paivana-http.sock|http://example.com/"
    373     </Location>
    374 
    375 Ready-made versions of both are shipped in `debian/examples/`, and
    376 installed by the Debian package into
    377 `/usr/share/doc/paivana-httpd/examples/`.  They are examples rather
    378 than drop-ins on purpose: the package only *recommends* a web server,
    379 so it must not create `/etc/nginx/` or `/etc/apache2/` on a system
    380 that has neither (Debian Policy 9.1.1).  Copy the one you want into
    381 place and enable it yourself.
    382 
    383 
    384 Trusted proxies
    385 ---------------
    386 
    387 `-f` on its own extends trust exactly one hop.  The chain is walked
    388 from the right and the walk stops at once, so the client is the
    389 *rightmost* element — the one the peer we accepted the connection from
    390 wrote.  Entries a client prepends to its own header sit to the left of
    391 that and cannot be promoted.
    392 
    393 What `-f` alone therefore rests on is that the server in front sets or
    394 appends those headers itself.  Appending is safe here, because the real
    395 peer ends up rightmost; passing the client's own headers through
    396 unchanged is not, and that is the failure to watch for, since nginx
    397 forwards a client-supplied `Forwarded` verbatim and Paivana prefers
    398 `Forwarded`.
    399 
    400 `TRUSTED_PROXIES` and `TRUSTED_PROXIES6` are what let the walk step
    401 further left, through hops you have listed, when there is more than one
    402 proxy in front:
    403 
    404     [paivana]
    405     TRUSTED_PROXIES  = 10.0.0.0/8;192.168.0.0/16;
    406     TRUSTED_PROXIES6 = 2001:db8::/32;
    407 
    408 The walk then steps over each listed proxy in turn; the first element
    409 that is not one of them is the client.  Each step leftwards is
    410 permitted only by the node being stepped over, so an element written by
    411 someone you did not list is as far back as the chain can be believed.
    412 
    413 Two things this does *not* do.  The address that connected is never
    414 matched against these lists — `-f` is what says the peer may speak for
    415 a client, and the lists only govern how far past it the walk may go.
    416 And an element that names no address (RFC 7239 `unknown`, an obfuscated
    417 identifier, a host name) is not skipped either: the walk stops there
    418 and Paivana falls back to the socket peer, which under `SERVE = unix`
    419 means no client address at all and a `POST /.well-known/paivana` that
    420 fails.  A front server that emits a `Forwarded` element it cannot fill
    421 in is therefore not a degraded paywall but a broken one.
    422 
    423 `X-Forwarded-Proto`, `-Host` and `-Port` are outside all of this: they
    424 are read as the leftmost value of the first such field line and the
    425 walk never vets them.  Under `-f` with no `BASE_URL` they are what
    426 Paivana rebuilds its own scheme and authority from, which is the
    427 residual reason to care about the front server's configuration even
    428 with `TRUSTED_PROXIES` set.
    429 
    430 Syntax notes, inherited from GNUnet's network-policy parser:
    431 
    432   - entries are separated *and terminated* by `;` — a missing trailing
    433     semicolon means nothing is parsed;
    434   - `TRUSTED_PROXIES6` does not tolerate spaces between entries
    435     (`TRUSTED_PROXIES` does);
    436   - `0.0.0.0/0` and `::/0` cannot be expressed: they are
    437     indistinguishable from the end of the list.
    438 
    439 Anything that parses to an empty list is refused at startup rather
    440 than silently trusting nobody.
    441 
    442 Put IPv4 proxies in `TRUSTED_PROXIES`, not in `TRUSTED_PROXIES6` as
    443 `::ffff:a.b.c.d`: addresses are folded to their IPv4 form before
    444 matching, so a mapped entry would never be hit.
    445 
    446 Set `BASE_URL` in the configuration file to the public HTTPS URL so
    447 that redirects and cookie domains are correct.  It may be omitted only
    448 when `-f` is given: the flag asserts that a reverse proxy in front of
    449 Paivana has already enforced a correct `Host`, which is what makes it
    450 safe to reconstruct our own URL from the request.  Without `-f` the
    451 client is assumed to have connected directly, `Host` is whatever it
    452 chose to send, and `BASE_URL` is therefore mandatory.
    453 
    454 
    455 Source layout
    456 -------------
    457 
    458     src/backend/          Main binary and all subsystems
    459       paivana-httpd.c     Entry point, scheduler, global state, shutdown
    460       paivana-httpd_reverse.c   Request-proxying state machine (core)
    461       paivana-httpd_pay.c       POST /.well-known/paivana handler
    462       paivana-httpd_cookie.c    Access-cookie keyed hash, Paivana ID
    463       paivana-httpd_templates.c Paywall template loading and rendering
    464       paivana-httpd_helper.c    Client IP / base URL helpers
    465       paivana-httpd_daemon.c    MHD daemon startup
    466       paivana_pd.c              GNUnet project-data descriptor
    467     src/frontend/         The paywall page served to unpaid visitors
    468       paywall.en.must.j2  Mustache template source (Jinja2)
    469       paywall.js          Payment identifier, QR code, long poll
    470       generate-paywall.py Renders the Jinja2 source at build time
    471     src/include/platform.h  GNUnet-style platform header (include first)
    472     src/tests/              Automated reverse-proxy and unit tests
    473     doc/prebuilt/           Git submodule: taler-docs (man pages)
    474 
    475 
    476 Architecture notes
    477 ------------------
    478 
    479 Single-threaded event loop: GNUnet scheduler drives both inbound HTTP
    480 (libmicrohttpd) and outbound requests (libgnunetcurl / libcurl multi).
    481 Running multiple `paivana-httpd` processes on the same port is
    482 supported as the main way to scale-up the system.
    483 
    484 Requests and responses are streamed in both directions: each is moved
    485 through a fixed-size ring buffer (REQUEST_BUFFER_MAX and
    486 RESPONSE_BUFFER_MAX, 256 KiB each by default) rather than assembled
    487 whole, so the size of a proxied body is bounded by nothing in Paivana.
    488 When the client cannot keep up, Paivana stops reading from the origin;
    489 when the origin cannot keep up, it stops reading from the client.  The
    490 memory an ordinary in-flight request costs is therefore the two buffers.
    491 Startup checks their product with the ordinary capacity
    492 (`CONNECTION_LIMIT - PAYMENT_CONNECTION_LIMIT`) against
    493 `RELAY_MEMORY_LIMIT`; with the defaults this is 352 * 512 KiB = 176 MiB.
    494 
    495 The process currently uses native `fd_set`s in both the MHD and curl
    496 scheduler integration.  `LimitNOFILE` therefore cannot safely raise
    497 concurrency beyond descriptor 1023.  The default 384-connection budget
    498 charges two descriptors per request and reserves 256 for non-request and
    499 transient use.  Moving to a poll/epoll integration is required before
    500 raising that ceiling.
    501 
    502 An upload is still bounded, by MAX_REQUEST_SIZE (1 MiB by default),
    503 because accepting one is a policy decision rather than a memory
    504 constraint.  A response is not bounded at all: an operator who wants to
    505 bound what their origin serves can do it at the origin.
    506 
    507 The MHD daemon is not started until paywall templates have been fetched
    508 from the merchant backend asynchronously.
    509 
    510 A 1xx interim response is not forwarded — RFC 9110 §15.2 asks a proxy
    511 to forward them, and Paivana instead drops them, because the response
    512 MHD is handed is a single final one.  `103 Early Hints`
    513 therefore does not reach clients through Paivana.  Its header fields
    514 are dropped with it rather than being merged into the final response,
    515 which is the part that would be actively harmful.  Trailer fields are
    516 dropped for the same reason (RFC 9110 §6.5.1 forbids merging them into
    517 the header section).
    518 
    519 An origin that accepts the connection but does not produce response
    520 *headers* within `UPSTREAM_TIMEOUT` (60 s) yields `504 Gateway
    521 Timeout`; one that cannot be reached at all yields `502 Bad Gateway`.
    522 The distinction matters because caches and monitoring retry the former
    523 and not the latter.  That clock is cancelled once the header section
    524 ends, and it is the only one that can still produce a status code:
    525 after it, the status is already on the wire.
    526 
    527 There is deliberately no ceiling on how long a request may take — a
    528 large download legitimately runs for as long as it runs.  What is
    529 bounded instead is a *stall*: `UPSTREAM_STALL_TIMEOUT` (60 s) is how
    530 long the origin may move no bytes in either direction.  The clock does
    531 not run while Paivana is itself holding the origin back because the
    532 client has not drained what has already arrived, so a client on a slow
    533 link is never mistaken for a slow origin.
    534 
    535 The MHD connection timeout does not cover any of this: a connection
    536 waiting on the origin is suspended, and MHD drops suspended connections
    537 from its timeout lists.
    538 
    539 Once the response headers have gone out the status cannot be retracted,
    540 so an origin that fails mid-body can only be reported as a framing
    541 error: a declared `Content-Length` that is not met, or a chunked
    542 response closed without its terminating chunk.  Both are required to be
    543 treated as failures by RFC 9112 §8.1.2.  The exception is an HTTP/1.0
    544 client receiving a response of unknown length, where the close *is* the
    545 framing and truncation is indistinguishable from success.
    546 
    547 `OPTIONS` carrying `Max-Forwards: 0` is answered by Paivana itself with
    548 an `Allow` list, as RFC 9110 §7.6.2 requires of an intermediary; any
    549 larger value is decremented before the request is passed on.
    550 
    551 
    552 License
    553 -------
    554 
    555 GNU Affero General Public License version 3 or later.
    556 See COPYING for the full text.
    557 
    558 
    559 Bug reports
    560 -----------
    561 
    562 Please report bugs at https://bugs.taler.net/.