Skip to content
Arbinel

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.

[proxy_cookie]
ENABLED = true
SECRET = <output of openssl rand -base64 32>
COOKIE_NAME = arbinel_signed_in
MAX_AGE = 1h

Give the proxy the same SECRET string.

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.

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 decoded SECRET as 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_AGE is 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 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:

http-request set-var(txn.arbinel_signin) req.cook(arbinel_signed_in)
http-request set-var(txn.arbinel_signin_exp) var(txn.arbinel_signin),field(1,.)
http-request set-var(txn.arbinel_signin_mac) var(txn.arbinel_signin),field(2,.)
http-request set-var(txn.arbinel_signin_want) var(txn.arbinel_signin_exp),hmac(sha256,"${ARBINEL_PROXY_COOKIE_SECRET}"),hex,lower
acl arbinel_signin_mac var(txn.arbinel_signin_want),strcmp(txn.arbinel_signin_mac) eq 0
acl arbinel_signin_fresh date,sub(txn.arbinel_signin_exp) lt 0
http-request set-var(txn.arbinel_signed_in) bool(1) if arbinel_signin_mac arbinel_signin_fresh
acl signed_in var(txn.arbinel_signed_in) -m bool

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.