Proxy sign-in cookie
A reverse proxy in front of Arbinel may route or limit signed-out traffic differently from signed-in traffic.
On its own, the proxy can only see that a session cookie exists, and anyone can send a session cookie with a made-up value.
With [proxy_cookie], Arbinel sets a second cookie that the proxy can verify with a shared secret.
Forgejo has no such cookie.
Give the proxy the same SECRET string.
Settings
Section titled “Settings”| Key | Default | Description |
|---|---|---|
ENABLED |
false |
Set the cookie. |
SECRET |
none, required | Standard base64 of at least 32 random bytes. Arbinel signs the cookie with the decoded bytes. |
SECRET_URI |
none | A file: URI to read SECRET from, instead of SECRET. Do not set both. |
COOKIE_NAME |
arbinel_signed_in |
Name of the cookie. It must differ from the session cookie and the remember-me cookie. |
MAX_AGE |
1h |
How long the cookie stays valid without activity. At least 1m. |
Arbinel logs an error and leaves the cookie off when a value is missing or invalid. An invalid section never stops the instance from starting.
Cookie
Section titled “Cookie”The value is <expiry>.<mac>:
<expiry>is the time the cookie stops being valid, in Unix seconds.<mac>is the lowercase hex HMAC-SHA256 of the<expiry>digits, with the decodedSECRETas the key.
Arbinel sets the cookie with the same path, domain and flags as its session cookie.
- Sign-in: Arbinel sets the cookie at every sign-in, whatever the method, and when the remember-me cookie signs a browser back in.
- Renewal: while the session is active, Arbinel renews the cookie once less than half of
MAX_AGEis left. - Removal: Arbinel removes the cookie at sign-out, and on the next request after the session stops signing anyone in. That happens when the session expires, the account is deleted, or the account may no longer sign in.
The cookie only tells the proxy that the browser recently held a signed-in session. Arbinel never accepts it as a credential.
The cookie is bound to its expiry and nothing else, so it keeps working when the browser’s address changes, as on mobile networks.
The cost is that a copy of the cookie works from anywhere until it expires.
Signing out removes it from the browser, but not from a copy.
MAX_AGE bounds how long a copy stays useful, so keep it short.
HAProxy
Section titled “HAProxy”HAProxy 3.x can check the cookie with its own converters.
Pass the secret in an environment variable, here ARBINEL_PROXY_COOKIE_SECRET, and add these lines to the frontend:
Then use signed_in where the configuration tested for the session cookie before.
The hmac converter decodes its key from base64, so the proxy and Arbinel use the same SECRET string.
If you change COOKIE_NAME, change the name in req.cook() as well.
To rotate the secret, change it in both places at the same time. The proxy then treats each browser as signed out for one request, until Arbinel replaces its cookie.