Sign-in security settings
These settings protect the Admin UI sign-in and the gateway's outbound fetches. They apply to users who sign in with a password, to anyone attempting to sign in, and to URLs that requests ask the gateway to fetch.
A real-world scenario
A company opens its Admin UI to every engineer so they can manage their own keys. Within a week a scanner on the internet starts guessing passwords at the sign-in page. The operator sets trusted_proxy_ranges to the load balancer's range so the gateway can tell real client addresses apart, keeps the default of ten failed attempts per minute per address, and turns on two-factor sign-in for password users. The scanner is blocked after ten tries and sees 429 for five minutes, the engineers set up an authenticator app at their next sign-in, and a developer who tried to use Summer2026! as a password is told it appears in a breach corpus and picks another.
Password policy
Every path that sets a password for a database user, /user/update, /user/bulk_update, the invitation claim flow and /user/password/change (the Change password page), checks the password against one policy.
general_settings:
password_policy_min_length: 14
password_policy_require_uppercase: true
password_policy_require_lowercase: true
password_policy_require_numbers: true
password_policy_require_special_characters: true
password_policy_check_breached_passwords: true
In the Admin UI, open Settings > Admin Settings > Security Settings and use the Sign-in protection card: set Minimum password length, choose On or Off for each character class rule, for Refuse passwords found in data breaches and for Turn off password sign-in when SSO is configured, then click Save. Every field carries help text that says what it does, what happens when it is on and off, its default and who should change it. Each saved field is stored in the database and shown with a Saved in database badge, a field set in config.yaml is shown as Set in config file and cannot be changed from the UI, and an empty field means the gateway default. The same change over the API is one call per field:
curl -X POST 'http://localhost:4000/config/field/update' \
-H 'Authorization: Bearer sk-admin' \
-H 'Content-Type: application/json' \
-d '{"config_type": "general_settings", "field_name": "password_policy_min_length", "field_value": 14}'
The minimum length defaults to 12 and cannot be set below 8, a lower value is raised to 8 rather than weakening the rule. The four character class requirements default to on. A password that fails is refused with 400 and a message listing every unmet rule, such as Password does not meet the required policy: must be at least 12 characters long, include a number. Special characters are detected in a Unicode aware way, so an accented letter does not count as one.
New passwords are also screened against a public breach corpus using a k-anonymity range lookup, so only the first five characters of the password's hash leave the gateway. A breached password is refused with 400. The check fails open when the corpus is unreachable. Turning it on protects users from passwords criminals already hold. Turning it off with password_policy_check_breached_passwords: false, or with the Refuse passwords found in data breaches switch, means no lookup leaves the gateway, which some privacy rules require, but leaked passwords are accepted. It is on by default, and air-gapped mode always skips it.
Failed sign-in lockout
Wrong passwords on the Admin UI are counted over a fixed window per source address and per address and username pair. Too many in one window blocks that key for a fixed time, and while blocked every attempt from it, right or wrong, is refused with 429 before the password is checked. Blocked pairs stop counting against their address, so one script stuck on one account cannot lock out an office behind a shared address. The master key over the API never passes through the throttle, so an admin can always recover.
general_settings:
trusted_proxy_ranges: ["10.0.0.0/8"]
max_failed_login_attempts_per_source: 10
max_failed_login_attempts_per_source_overrides:
"10.1.2.3": 200
"10.9.0.0/16": 0
failed_login_window_seconds: 60
failed_login_block_seconds: 300
| Key | Default | Meaning |
|---|---|---|
max_failed_login_attempts_per_source | 10 | Failures allowed from one address across every username in the window. Half of it, at least 1, is the allowance for one username from that address. |
max_failed_login_attempts_per_source_overrides | unset | Per address or CIDR overrides, most specific range first. 0 exempts the address from both limits. |
failed_login_window_seconds | 60 | Window counted from the first failure. |
failed_login_block_seconds | 300 | Length of a block. Refused attempts do not extend it. |
The lockout fields sit in the same Sign-in protection card of the Admin UI. Per-address limit overrides takes one override per line, the address or CIDR range, a space, then the limit, so the example above is entered as 10.1.2.3 200 and 10.9.0.0/16 0. Clearing a field and saving removes the stored value and returns to the default.
The per address limit only runs when trusted_proxy_ranges is set, because without it the peer address may be a shared ingress. Set it to the proxies in front of the gateway, or to an empty list when clients connect directly. IPv6 sources are grouped by /64. Counters live in the coordination Redis when one is configured, otherwise each worker counts on its own and the effective limit is multiplied by the worker count, which the gateway warns about at startup. SPANWAY_DISABLE_LOGIN_RATE_LIMIT=true turns the throttle off.
Two-factor sign-in
Admin UI username and password sign-ins can require a code from an authenticator app (TOTP, RFC 6238, six digits every 30 seconds, which Google Authenticator, 1Password, Authy and similar apps use). It applies to /login, /v2/login, /v3/login and to the environment admin set with UI_USERNAME and UI_PASSWORD. SSO sign-ins are not affected, since the identity provider owns its own second factor, and neither are API calls with the master key or a virtual key.
Who is asked for a code
A user who has set up an authenticator app is always asked for a code. A user who has not is asked to set one up at their next sign-in when two-factor sign-in is required for them, either for everyone with
general_settings:
require_mfa_for_password_login: true
which a proxy admin can also turn on in the Admin UI under Router Settings, on the General tab, and which is part of the free gateway,
or by an organization they belong to, as their home organization or through a membership, with require_mfa: true on /organization/new, /organization/update or PATCH /v2/organization/{organization_id}. Proxy admins and the organization's admins can change it, and turning it on needs an enterprise license. An organization admin changes it for their own organization in the Admin UI on the organization's Settings tab. Organization admins may change the organization's name, require_mfa and metadata this way, while models, budgets, rate limits, vector stores, MCP servers and the data policy stay with proxy admins, so an update that sends one of those from an organization admin is refused with a 403 that names the field. Setting a requirement does not end existing Admin UI sessions, so it takes effect as each user next signs in, at most SPANWAY_UI_SESSION_DURATION later.
When two-factor sign-in is required and the database is unreachable, password sign-in fails with 503 instead of letting the user in without a code. The master key over the API is the way in while the database is down.
How the sign-in works
The second-factor routes below are called by the Admin UI sign-in page and are left out of the published API reference, like the other sign-in routes. Their errors are listed in the errors table and the error reference. After a correct password, /v2/login and /v3/login answer {"mfa_required": true, "enrollment_required": false, "mfa_token": "swmfa_..."} instead of a session, and no session key exists yet. The dashboard then posts the code to /v2/login/mfa with {"mfa_token": "...", "code": "123456"}, or {"mfa_token": "...", "recovery_code": "..."}, and gets the same answer a password-only sign-in would have given. When enrollment_required is true it first calls /v2/login/mfa/enroll for the otpauth:// URI and secret, then /v2/login/mfa/enroll/confirm with the first code, which also returns ten recovery codes. The form post to /login cannot carry a second factor, so for an account that needs one it starts no sign-in and redirects to the dashboard sign-in page, where the user enters the password again and then the code.
The mfa_token lasts five minutes and works once. It allows five code attempts in total, and each attempt is counted before its code is checked, so guesses sent in parallel cannot go past the limit. After that the user signs in again. The challenge is stored in the database, so every replica sees the same attempt count with or without Redis, and each wrong code also counts as a failed sign-in for that username in the lockout above. A code is accepted one 30 second step either side of the server clock and only once, so a code seen over someone's shoulder cannot be replayed.
Secrets and recovery codes
Authenticator secrets are encrypted with the salt key (SPANWAY_SALT_KEY, or the master key when no salt key is set), the same way other stored credentials are, and both a master key regeneration through /key/regenerate with new_master_key and the SPANWAY_MIGRATE_FROM_MASTER_KEY migration re-encrypt them. Recovery codes are 16 characters of base32 (80 random bits), shown once and stored as hashes. Each one works once.
Managing your own setup
A signed-in user manages their own setup from the Two-factor sign-in card on the Change password page, or over the API with their Admin UI session. These calls refuse any other credential.
| Route | What it does |
|---|---|
GET /user/mfa | Whether it is set up, whether it is required, and how many recovery codes are left. |
POST /user/mfa/enroll | Starts setting up an app and returns the otpauth:// URI and secret. |
POST /user/mfa/enroll/confirm | Finishes with a code {"code": "123456"} and returns ten recovery codes. |
POST /user/mfa/recovery_codes | Replaces the recovery codes, given a current code. |
POST /user/mfa/disable | Turns it off, given a current code. Refused with 403 while it is required for the user. |
Lost authenticator
A user who has lost both their authenticator and their recovery codes asks a proxy admin, who calls POST /user/mfa/reset with {"user_id": "..."}. It removes the setup, signs the user out of every Admin UI session and writes an audit row. If two-factor sign-in is required for them they set it up again at their next sign-in. Enrollment, removal, reset and recovery code changes are all written to the audit log under Spanway_UserMFA.
Trusted reverse proxies
trusted_proxy_ranges does two jobs. It names the proxies whose X-Forwarded-For is believed when attributing a sign-in attempt to a source address or checking an IP allow-list, walking the header from the right and taking the first hop that is not a trusted proxy so a forged leftmost entry cannot spoof the client. It also gates the header based authentication paths, enable_oauth2_proxy_auth and custom_ui_sso_sign_in_handler, which refuse identity headers unless the direct peer is inside a trusted range. For the sign-in throttle, a list that contains an entry that is not a valid address or CIDR turns the per address limit off, and the header based auth paths skip such an entry with a warning.
In the Admin UI the ranges are edited in Settings > Admin Settings > Security Settings under Network allowlists, as Trusted reverse proxies, one range per line. Enter [] when clients connect directly, which saves an empty list and turns the per address sign-in limit on with the peer address as the source. Every line must be an IP address or a CIDR range such as 10.0.0.0/8 or 2001:db8::/32. The card refuses a host name or a range like 10.0.0.0/33 before saving with "Not an IP address or CIDR range:" and the bad entries, and POST /config/field/update answers 400 Invalid trusted_proxy_ranges: Value error, not an IP address or CIDR range: 'lb.internal' and stores nothing, the same for mcp_trusted_proxy_ranges. This keeps one mistyped line from quietly turning the per address sign-in limit off.
The same address is stored as requester_ip_address in spend logs, and the MCP endpoints use it too when use_x_forwarded_for is on. MCP still accepts the older mcp_trusted_proxy_ranges, and when both are set it trusts only proxies inside both lists, and mcp_xff_num_trusted_hops to read a fixed entry from the right of the header instead.
URL allow-lists
Requests can carry URLs the gateway fetches on the caller's behalf, image and file URLs, MCP server URLs and OpenAPI specs among them. Without a check, any caller could ask the gateway to fetch an address inside your network, such as a cloud metadata endpoint that hands out credentials, and read the answer. These four settings decide what the gateway may reach. All of them live in general_settings and only proxy admins can change them.
| Setting and Admin UI label | What it does in plain words | When it is on or set | When it is off or empty | Default | Risk and who should change it |
|---|---|---|---|---|---|
user_url_validation, Block private destinations in user-supplied URLs | Keeps callers from using the gateway to reach your internal network. | The gateway resolves each hostname in a request and refuses private, loopback and link local destinations. | Any caller can make the gateway fetch internal addresses, cloud metadata included. | On | Leave it on. Turn it off only on a closed network where every caller is trusted, and prefer adding single hosts to the list below. |
user_url_allowed_hosts, Allowed hosts for user-supplied URLs | Opens the block for a few internal hosts you trust, for example an internal OpenAPI server you want to expose as MCP tools. | Listed hostname or hostname:port entries, with brackets for IPv6, are allowed even when they resolve to a private address. | Only public destinations are allowed. | Empty | Every listed host can be reached by any caller, so add only hosts that are safe to expose. |
provider_url_destination_allowed_hosts, Allowed provider destination hosts | Lets a request send its provider call to a host you name, by giving a URL as the model, the file_id or a fallback target, for example a team's own model server. | A URL that points at a listed host is accepted. | Every URL valued model, file id or fallback target is refused with 400, which stops callers from sending prompts and provider keys to a host you do not control. | Empty | Add only hosts you run or trust. |
deployment_url_allowed_hosts, Allowed deployment hosts for team admins | Lets team admins add models that run on these internal hosts. | Team admins may point a deployment at a listed host, given as hostname, hostname:port or an origin, over http too. | Team admins can only use public provider addresses. | Empty | A listed host is reachable from every team admin's deployments, so add only model servers meant for teams. Proxy admins are never restricted. |
All four settings are also editable in the Network allowlists card of Settings > Admin Settings > Security Settings: Block private destinations in user-supplied URLs is the user_url_validation switch, and the three host lists take one entry per line. Each control carries the same explanation as help text. Changes apply to new requests once saved, without a restart. Clearing one of these fields in the card, or calling POST /config/field/delete for it, removes the stored value and puts the default back into effect, so the private destination guard turns back on and a removed host list is emptied. The gateway that served the call applies it at once and every other gateway applies it at its next database sync, within proxy_config_reload_interval_seconds (30 seconds by default), without a restart. A value that the config file sets stays in effect, because the file owns that key. Every save and every reset writes an audit row, see audit logs.
To reset the guard from the command line, with an admin key in SPANWAY_API_KEY:
curl -sS -X POST "http://localhost:4000/config/field/delete" \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"config_type": "general_settings", "field_name": "user_url_validation"}'
POST /config/field/delete is listed in the API reference as Reset one general setting to its default. Clearing the field in the card does the same thing without the API.
Expected result: {"config_type": "general_settings", "field_name": "user_url_validation", "message": "Field user_url_validation reset to its default"}. The route answers 400 with {"error": "Field name=user_url_validation not in config"} when the database holds no general settings yet, {"error": "Invalid field=... passed in."} for an unknown setting, and the not allowed message for a key that is not a proxy admin.
A deployment's endpoint URLs get the same treatment when someone other than a proxy admin writes them. When a team admin creates, updates or tests a deployment through /model/new, /model/{id}/update, /model/update or /health/test_connection, the gateway resolves api_base, base_url and every other endpoint field (including URLs inside JSON credentials) and refuses private, loopback, link local and cloud metadata addresses, hostnames that do not resolve, URLs that carry credentials, plain http URLs, and region or location values with anything other than letters, digits, - and _. Requiring https with certificate verification means a hostname that is rebound to an internal address after the check fails the TLS handshake. Providers that default to a local server when no api_base is set, such as Ollama, llamafile and vLLM, need an explicit public api_base, and configurable_clientside_auth_params may only list api_key. Deployments whose endpoint fields were last written by a team admin are checked again before each call and before each background health check, so a hostname that later resolves to an internal address is refused too. A call refused because the hostname did not resolve returns a retryable 503. If your teams legitimately run internal model servers, list them in deployment_url_allowed_hosts in general_settings, as hostname, hostname:port or an origin such as http://llm.corp.internal:8000. Listed hosts may use http. A proxy admin can write any URL, and deployments a proxy admin configured, including team deployments, are never checked, even when they point at an internal host.
Request body cap
The gateway refuses oversized requests before it even checks the key, so nobody can tie up memory by sending a huge body. Every content type counts, file uploads included. The cap is set with general_settings.max_request_size_mb. When it is not set, the cap is 100 MB. Set a larger number if your clients upload bigger files, or 0 to turn the cap off. A request over the cap gets a 413 with {"error": "Request size is too large. Max size is 100 MB"}.
general_settings:
max_request_size_mb: 250
Changing where a stored secret is sent
Saved models, credentials, search tools, guardrails, pass-through endpoints, MCP servers, agents and logging callbacks keep their keys on the gateway, and edit forms show them masked. When you change the address one of these objects sends its key to, such as api_base, target, an MCP server url or token_url, or a callback host like LANGFUSE_HOST, you have to type the key again in the same save. If the key is left out, left blank or sent back in its masked form, the gateway refuses the update with a 400 that names the address and the key it would have reused, and nothing is saved. This keeps anyone who can edit an object, but cannot read its key, from pointing the key at a server they control.
Edits that keep the same address work as before, and a masked key you send back unchanged keeps the stored value.
The same rule covers key and team callback_vars on /key/update and /team/update, an agent's agent_card_params.url, an MCP server's global env_vars values, and a pass_through_endpoints list replaced through /config/update or /config/field/update. Sending back stored ciphertext, a masked value, or a secret copied from another key, team or endpoint counts as reusing the stored key, so a new address needs the key typed again.
Release integrity and vulnerability fixes
Every release is signed and ships an SPDX SBOM for each artifact it publishes, the container images, the Helm charts, the spanway-client and @spanway/client clients, and the VS Code extension. The Terraform provider gets its SBOM once it is published to a registry. The gateway itself is published only as container images with its code compiled inside, and the release refuses to tag an image in which any first-party Python source remains. Images, charts and release files are signed with cosign, with a key held in a cloud key management service whose public key is attached to every release, as the release cycle page explains. Each release also includes an OpenVEX document that states the status of every known vulnerability in the released dependencies, with a fix deadline of 7 days for critical findings, 30 days for high, 90 days for medium and 180 days for low, counted from the day a fixed upstream release exists. The release assets section of the container images page lists the files, how to verify them and the full SLA.
Step by step
-
Set the password policy, the lockout values and
trusted_proxy_rangesingeneral_settingsas shown above and roll the gateway. -
Turn two-factor sign-in on for everyone. In the Admin UI open Settings, then Router Settings, the General tab, switch on
require_mfa_for_password_loginand save, or setrequire_mfa_for_password_login: truein the config. An organization admin turns it on for one organization with Require two-factor sign-in on the organization's Settings tab. -
Test the policy by setting a weak password on a test user:
curl -X POST http://localhost:4000/user/update \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"user_id": "test-user", "password": "short"}'Expected result: 400 with
Password does not meet the required policy: must be at least 12 characters long, include an uppercase letter, include a number, include a special character. -
Sign in to
/ui/loginwith the test user. After the password, the page asks you to set up an authenticator app, shows the setup key, accepts the first code and shows ten recovery codes once. The next sign-in asks for a code. -
As the user, read your own two-factor state from the signed in dashboard session:
curl http://localhost:4000/user/mfa \-H "Authorization: Bearer spanway-ui-session" \-b "token=$DASHBOARD_SESSION_COOKIE"The dashboard session cookie is named
token. The gateway reads it only when the request also sends the placeholder keyspanway-ui-session, which is what the dashboard does. A virtual key or the master key is refused with 403, because these routes accept only an Admin UI session.Expected result:
{"enrolled": true, "required": true, "recovery_codes_remaining": 10}.
Errors
| Status | Where | Meaning | Fix |
|---|---|---|---|
400 Password does not meet the required policy: ... | /user/update, /user/bulk_update, /user/password/change, invitation claim | The password breaks one or more rules, all are listed. | Choose a password that meets every listed rule. |
400 This password appears in known data breaches and cannot be used. Please choose a different password. | the same routes | The breach corpus knows the password. | Choose another password, or turn the check off with password_policy_check_breached_passwords: false. |
429 Too many failed sign-in attempts. Try again later. | /login, /v2/login, /v3/login | The address, or the address and username pair, is blocked after too many failures. The Retry-After header gives the seconds left on the block. | Wait the Retry-After seconds, or exempt the address in max_failed_login_attempts_per_source_overrides. The master key over the API is never throttled. |
| 503 on password sign-in | sign-in | Two-factor sign-in is required and the database is unreachable. | Restore the database. Use the master key over the API meanwhile. |
401 Invalid code | /v2/login/mfa and the /user/mfa routes | The code is wrong, reused or outside the 30 second window either side. | Enter the next code from the app. |
401 This sign-in has expired or was already used. Sign in again. | /v2/login/mfa, /v2/login/mfa/enroll, /v2/login/mfa/enroll/confirm | The mfa_token was used for five attempts, is older than five minutes or was already used. | Sign in again with the password. |
401 This account no longer exists | /v2/login/mfa routes | The user was deleted between the password and the code. | Ask a proxy admin to recreate the user. |
403 Two-factor settings can only be changed from a signed-in Admin UI session | the /user/mfa routes | The call used a virtual key or the master key. | Sign in to the Admin UI and use its session. |
403 Two-factor sign-in is required for this account and cannot be turned off | POST /user/mfa/disable | The gateway or an organization requires it. | Only a proxy admin can remove it with POST /user/mfa/reset. |
403 Only proxy admins can reset two-factor sign-in | POST /user/mfa/reset | The caller is not a proxy admin. | Ask a proxy admin. |
409 Two-factor sign-in is not set up yet for this account | /v2/login/mfa | The account has no authenticator app yet. | Finish setup through /v2/login/mfa/enroll first. |
409 Two-factor sign-in is already set up. Enter a code from your app. | /v2/login/mfa/enroll | Setup was already finished. | Sign in with a code instead. |
409 Two-factor sign-in is already set up. Disable it first to start over. | POST /user/mfa/enroll | Setup was already finished. | Disable it with a current code, then enroll again. |
409 Two-factor sign-in is not set up for this account | /user/mfa/recovery_codes, /user/mfa/disable, /user/mfa/reset | There is nothing to change. | None needed. |
500 Master key is not set | /v2/login/mfa routes | The gateway cannot sign a session without a master key. | Set SPANWAY_MASTER_KEY. |
500 No database connected | the two-factor routes | Two-factor setups live in the database. | Set DATABASE_URL. |
| 400 naming an address and a key | any edit that changes where a stored secret is sent | The new address needs the key typed again. | Send the key in the same save. |
413 Request size is too large. Max size is ... MB | any route | The request body is over max_request_size_mb. | Send a smaller body or raise max_request_size_mb. |
| 403 that names a field | /organization/update by an organization admin | Only name, require_mfa and metadata may be changed by organization admins. | Ask a proxy admin for the other fields. |
Logs
| Level | Line | Meaning | Action needed |
|---|---|---|---|
| WARNING | Running N workers but Redis is not configured. Failed Admin UI sign-in attempts are counted per worker ... | No coordination Redis is configured, so each worker counts failures on its own and the effective limit is multiplied by the worker count. | Configure the coordination Redis. |
| WARNING | trusted_proxy_ranges is not set or not a valid list of ranges, so failed Admin UI sign-in attempts are limited per source address and username only ... | The per address limit is off. | Set trusted_proxy_ranges, or [] when clients connect directly. |
| WARNING | Invalid address or range '...' in trusted_proxy_ranges; skipping | An entry is not a valid address or CIDR, the header based auth paths skip it. | Fix the entry. |
| WARNING | Admin UI sign-in blocked for N seconds after too many failures; scope=user username=... source=... | A block started for an address (scope=source) or an address and username pair (scope=user). An audit row is written too. | None if it is an attacker. Check the source when it is one of your offices. |
| WARNING | Admin UI sign-in refused: the user is blocked for N more seconds; username=... source=... | A sign-in arrived during a block and was refused with 429. | None, unless a real user is locked out, then wait or add an override. |
| WARNING | Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: ... | The coordination Redis is unreachable. Each worker counts on its own until it is back. | Check the Redis connection. |
| WARNING | Breached-password check skipped, HIBP lookup failed: ... | The breach corpus could not be reached, so the new password was accepted without the check. | Allow outbound HTTPS to the breach corpus, or turn the check off. |
Response security headers
Every gateway response carries headers that stop browsers from misusing it: X-Frame-Options: DENY and Content-Security-Policy: frame-ancestors 'none' stop another site from showing the Admin UI inside a frame to trick a user into clicking, and X-Content-Type-Options: nosniff stops a browser from guessing a file type. They are always on.
SPANWAY_ENABLE_HSTS=true also sends Strict-Transport-Security: max-age=31536000; includeSubDomains, which tells browsers to use only HTTPS for your gateway's domain and its subdomains for a year. Turn it on only when every one of those addresses is served over HTTPS, because a browser that has seen the header refuses plain HTTP to them until it expires. It is off by default, and an operator who owns the domain should change it.
Related
- Admin UI SSO for identity provider sign-in, which has its own second factor.
- Account page for the Two-factor sign-in card users see.
- IP allow-lists for the other use of
trusted_proxy_ranges. - Release cycle and container images for signatures, SBOMs and the fix SLA.
- Audit logs for the rows the two-factor routes, the sign-in lockout and the security settings write.
- Environment variables for
SPANWAY_DISABLE_LOGIN_RATE_LIMITandSPANWAY_ENABLE_HSTS.