The sign-in page is /auth/login. This path is a contract with Traefik ForwardAuth and with the applications. It never changes.
Measures
Five measures protect or hide the page. Two of them are real protections. Three of them are obscurity.
| Measure | Kind | What it does |
|---|---|---|
| 1. Anti-enumeration | Real protection | An outside observer cannot learn which logins exist. |
| 2. Hide the product | Obscurity, not security | The page does not name the product or its version. |
| 3. Anti-bot checks | Real protection, limited | A simple script that posts at once, or that fills every field, fails. |
| 4. Script minification | Obscurity, not security | The served script has no comment and no long name. |
| 5. Random names and structure | Obscurity, not security | The classes, the identifiers and the structure of the page are not fixed. |
Obscurity does not stop an attacker who reads the page. It only removes the easy marks. Do not count on measures 2, 4 and 5 for security. The limiters and Argon2 stay the protection against password attacks.
None of the five measures adds a configuration key, so no new default exists to document. The box "Remember me" has its own keys. The second factor adds the keys authentication.mfa and authentication.totp_key. See The box "Remember me" and The second step.
1. Anti-enumeration
An attacker can try to learn which logins exist. The portal gives the same answer for each cause of a refusal.
What the observer sees
These cases give the same answer. Each case gets status 401, the text "Invalid login or password" and the same headers. The page has the same structure. Only the anti-CSRF token, the form token and the inert elements of measure 5 change. The size changes with the inert elements, and the change does not depend on the cause.
- The login does not exist.
- The login is the superadmin, and the password is wrong.
- The login is an ordinary account, and the password is wrong.
- The login is longer than any login can be.
- The password is right, but the check of the form fails (see measure 3).
Each of these requests runs exactly one Argon2 check. For an unknown login, the check uses a dummy hash that has the same cost parameters as a hash of the portal. Each request adds one failure to the per-IP budget and to the global budget. Each request adds one to the metric portal_login_attempts_total{result="failure"}.
With a shared database, the portal reads the accounts before each sign-in, for every login. The read has a limit of one for each second. If only an unknown login started the read, the time would tell the observer that the login is unknown. So the read starts for every login.
The limit of one read for each second does not apply to a request with a valid session. When the directory of an instance does not know the account of such a session, the instance reads the accounts at once. Requests that arrive together wait for one read. The session ends only when the database confirms that the account does not exist. When the database does not answer, the request fails and the session stays. A new account on another instance therefore never loses its session.
The tests an_unknown_login_a_wrong_password_and_a_failed_form_check_get_the_same_refusal and a_failed_form_check_uses_the_budget_of_the_failed_sign_ins (in src/http/cluster_tests.rs) check this. They compare the status, the canonical form of the body and the headers. The canonical form is the body without the inert elements, with the attributes and the head in a fixed order. The tests do not measure time. They count the Argon2 checks, because the count does not depend on the load of the machine.
What stays different
An observer can still see these differences. None of them depends on whether the typed login exists, except item (b).
- (a) A refusal of a limiter has status 429 and the header
Retry-After. It does not run Argon2, so it is faster. The observer learns the state of the limiter for his own address, or for all clients. The observer learns nothing about the login. A limiter that hid its refusal would let an attacker use the Argon2 budget of the server. - (b) The superadmin login has its own budget in the global limiter. While one budget is locked out, the answer tells whether the typed login is the superadmin login. An anonymous attack must not lock out the administrator, so the budgets are separate. The superadmin login is not a secret: each identity token carries it.
- (c) A good sign-in has status 303 and a cookie. This difference is the purpose of the page.
- (d) A bad body, a bad
rdorsig, a wrong content type or a password that is too long gets status 400 or 415. A form that stayed open too long gets status 403. These answers do not depend on the login. - (e) An account of the file can have a
password_hashthat was made with other Argon2 cost parameters. The check then takes another time than the check against the dummy hash. Make these hashes withportal hash-password, so that all hashes have the same cost. - (f) A busy server queues the checks behind the semaphore
security.max_concurrent_password_checks. The queue time is the same for every login.
No state "disabled" or "locked" exists for an account. A deleted account is an unknown login. An account of the file that has no password_hash is an unknown login for the sign-in. The portal has no per-account lockout, because such a lockout would show which accounts exist.
The fields rd and sig
The fields rd and sig are the return target and its HMAC. They do not depend on a login. A value that is not valid is replaced by / on the page. A value that is not valid in a POST gives status 400. An attacker cannot make a valid pair without the session secret.
2. Hide the product
The page does these things:
- The title of the page is
Authentication. It has no name. - The page has no comment, no
generatortag and no version. The server sends noServerheader and noX-Powered-Byheader. - The stylesheet and the script have neutral paths:
/auth/a/<hash>.cssand/auth/a/<hash>.js. The hash is the first 8 bytes of the SHA-256 of the file. The plain paths/auth/style.cssand/auth/assets/theme.jsstill work, because the settings pages and old links need them. - The assets have no comment and no name of the product. The key of the browser storage for the theme is
ui-color-mode. - The cookie of the sign-in form is
lc(__Host-lcover HTTPS). It carries no name of the product. - ForwardAuth lets the neutral asset paths pass without a session, as it does for the plain paths.
- The sign-in pages, the code step and the status pages have no logo and no name of the product. They have no icon file. Their only icon link is the empty icon
data:,. The browser does not ask for/favicon.ico, and it does not show an icon that it kept from a signed-in page. - A visitor with no session gets the answer of an unknown path for the path of the tab icon. The path follows from the content of the file, so a 404 for this path only would show that the product runs here. A test compares the two answers.
- The Content-Security-Policy has
img-src 'self' data:. Thedata:source is there for the empty icon only. No page loads a picture from a data URL. - No page body has the logo or the name of the product, also after sign-in. A test checks the main pages. It has a list of the technical identifiers that stay, such as
service:portalin a grant. - After sign-in, the tab shows the name of the instance (
server.name) in its title and the built-in logo as its icon. The keyui.faviconset to"none"removes the icon. The server sends the icon to a signed-in browser only, so a visitor cannot use it to find the product.
The page does not hide one thing, on purpose. The default name of the session cookie is __Host-portal. The key session.cookie_name sets another name. A change of the default would end all sessions at the upgrade, so a site that wants a neutral name sets the key. The session cookie shows only after a sign-in, and it goes to the applications, because it has Path=/.
What still identifies the product
- The path
/auth/loginand the routes/auth/verify,/auth/logoutand/auth/denied. They are a contract. - The query
?rd=...&sig=...of the redirect to the page. - The names of the form fields:
login,password,csrf,rd,sigandtoken. - The headers of the security policy, for example the text of the Content-Security-Policy.
- The visual design of the card, and the behavior of the page.
- The session cookie, until the site sets
session.cookie_name. - The settings pages (
/auth/settings/...). They keep the plain class names and the plain files, and they need a session. The script/auth/assets/settings.js?v=<version>and the metrics path stay plain too. The operator controls the metrics path. The Inbox paths/readyzand/api/versionare public when the blockinboxexists, and/api/versionshows the version.
3. Anti-bot checks
The form has three checks. All of them work without JavaScript.
The signed token
The hidden field token holds the time of issue and an HMAC. The HMAC covers the time and the anti-CSRF token of the browser. The server signs with the session secret. The check has no state on the server, so any instance with the same secret can check it.
- The token is too new when the submit comes less than 1 second after the display. A person cannot type a login and a password so fast.
- The token is too old after 12 hours. This is the life of the anti-CSRF cookie. A person with an old page gets the page "The page was open too long" again, with a new token. The answer is the same as for an expired anti-CSRF cookie.
- A token that is absent, damaged, or signed for another anti-CSRF token is a failed check.
- A clock on another instance that runs behind by more than the time of the person makes a token too new. Keep the clocks of the instances in step.
The token does not stop a replay in its 12 hours. The anti-CSRF token and the token are bound to each other, but a script can read both from the page. The token forces a script to read the form and to wait one second.
The trap field
The form has a field website in a block with the class hp. The stylesheet hides the block (display: none). The block has aria-hidden="true" and inert. The field has tabindex="-1" and autocomplete="off". It has the attributes that the password managers 1Password, Bitwarden and LastPass read to ignore a field.
A keyboard and a screen reader cannot reach the field, and a person never fills it. A script that fills every field of the form fills it, and the check fails.
A failed check looks like a wrong password
A failed check does not give a different answer. The sign-in goes the whole way: the Argon2 check, the limiters, the metrics and the log. The end of the sign-in refuses, whatever the password. The answer is the one of measure 1: status 401 and the same page. The time is the same.
The check counts as a failed sign-in in the per-IP budget, in the global budget and in portal_login_attempts_total{result="failure"}. The metric portal_login_form_check_failures_total counts the failed checks alone. It is a part of the failures.
The log line login_failed has the field reason: credentials or form_check. The reason is in the log only. The page never shows it.
A password manager can submit the form less than 1 second after the display. The answer is then "Invalid login or password". The new page has a new token, and a second submit works. This cost is accepted.
The names of the login and password fields
The names login and password stay stable. Random names for each render are not used, because no test can show that every password manager still works. Browsers and password managers keep the name of a field with the saved credential, and they use it to find the form again. A random name puts the fill and the prompt to save at risk. The gain is small: a script finds the fields by the type password. The fields keep autocomplete="username" and autocomplete="current-password", and the password field has type="password".
4. Script minification
The script that every page loads is web/theme.js. The server makes a smaller copy once, at the first request. It uses a small transform in src/ui/minify.rs. The transform removes the comments and the layout and gives short names to the local names. It needs no tool at build time and adds no dependency.
The transform is a tokenizer, not a parser. It accepts only the JavaScript that the script uses. It refuses a template literal and a regular expression literal. It does not rename a script that has arrow functions, classes, eval or with, and it does not rename in a declaration with a comma.
A test makes sure that the shipped script is in this subset. If the transform fails, the server sends the source.
The stylesheet gets the same treatment: the comments and the layout go, and strings stay as they are. The file has a neutral path with a hash of the content. The browser can keep it for one year (immutable). The CSP stays strict: the file is external, and there is no eval and no inline script.
The project does not flatten the control flow, encode strings or add dead code. Each of them needs a parser or a new tool in the build, and none of them gives security. The transform does not touch settings.js, because the sign-in page does not load it.
The tests check that the served script has no comment and no name of the product. They also run node --check on it. The test skips the check when the image has no node.
5. Random names and structure
The sign-in page, the status pages and the launcher load only two files. The files are the shared stylesheet web/portal.css and the theme script web/theme.js. The status pages are "Page not found", "Access denied" and "Authenticated". This measure applies to these pages. The settings pages need a session and load other files. They keep the plain names.
The code is in src/ui/mask.rs. The renderers write plain names. A last step, the mask, changes the page before the server sends it. This way the renderers and their tests do not change.
The names
- Each class, each identifier (
id,for,aria-labelledby,href="#...") and each data attribute of the shared files gets a mapped name. A mapped name has 6 to 10 characters froma-z0-9and starts with a letter. - The mapped name is the HMAC-SHA-256 of the plain name. The key of the HMAC derives from the session secret with a fixed label. The secret is the one that signs the form token.
- Each instance that has the same secret makes the same names. No instance keeps a state, so an upgrade one instance at a time works. A restart does not change the names. A new session secret changes them.
- The same map rewrites the stylesheet and the script. In the stylesheet, only the selectors change. In the script, only the strings that name the class
jsand the data attributes change. The values do not change. - The mapped files have their own paths
/auth/a/<hash>.cssand/auth/a/<hash>.js. The hash follows the mapped content. The files are the same for all visitors, so the browser keeps them for one year (immutable). - The settings pages, and the plain paths
/auth/style.cssand/auth/assets/theme.js, keep the plain files. A browser that visits both kinds of page loads both pairs of files. A page that loads the plain files and a page that loads the mapped files never mix their names. - ForwardAuth lets the mapped paths pass without a session, as it does for the plain paths.
- A launcher of an account that receives notifications loads a third file, the script of the notifications (
web/notify.js). It has a neutral path/auth/a/<hash>.js. The pass changes no string of this script. The script finds its elements by data attributes, and the shared stylesheet has the classes of its parts. The markup of the inbox icon, of the popover and of the toasts goes through the same pass as the rest of the launcher. The settings pages load the file at/auth/assets/notify.js?v=<version>.
The structure
At each render, the mask makes these changes. A change has no effect on the look or on the behavior.
- It inserts 0 to 3 inert elements at random places in the body. An inert element is a wrapper (
divorspan) around an element of the page, with the ruledisplay: contents. It can also be an emptydivwithdisplay: noneandaria-hidden="true". An inert element has a mapped class and no other attribute. It has no content of its own, no tab stop and no role. - A wrapper never encloses a field, a button or an element of the sprite. A
spannever encloses a block. The mask puts adivonly where the content of the parent can be a block. - It changes the order of the attributes of each tag.
- It changes the order of the elements of the head.
<meta charset>stays first. The order has no effect for the stylesheet and the script, because the browser loads both before the first paint.
The stylesheet of these pages has no rule that depends on the structure. It has no child combinator (>), no sibling combinator (+, ~) and no :first-child or :first-of-type. A test reads the stylesheet and fails if such a rule appears again. A rule for a case that needs the structure uses a class. A selector with :has() is allowed when its argument is a descendant, because a wrapper that the pass inserts does not break it. The labels of the sign-in card that move up use it.
The order of the login field and the password field does not change. The trap field stays after them. The form fields and their attributes stay in the form. Password managers find them as before.
What still identifies the product
This list is complete as far as the authors know. The measure is obscurity.
- The names of the form fields:
login,password,csrf,rd,sig,tokenand the trapwebsite. The attributesautocomplete,data-lpignore,data-1p-ignoreanddata-bwignore. Password managers and scripts need them. - The text, the number and the kind of the elements, and their order. The form has two fields, a trap and a button.
- The names of the CSS custom properties (
--bg,--accent-filland others) and the name of the keyframespulse-up. The values of the rules and the media queries also stay. The mask maps only classes, identifiers and data attributes. - The values of the theme (
dark,light,system), thearia-*attributes,role,typeand the keyui-color-modeof the browser storage. - The mapped names are fixed for one deployment. A reader that learns them once finds them on every request. They differ from one deployment to another, and they change when the session secret changes.
- The mapped files are served from
/auth/a/, and both have a hash in the name. - The cost of the page: size, number of requests and the two files.
- The behavior: the theme switch, the form flow, the cookie
lcand the headers.
Tests
- Two instances with the same secret make the same names and the same files. Two secrets make other names and other files.
- A name has 6 to 10 characters, it starts with a letter, and no two plain names give the same mapped name.
- The login page, the denied page, the error page and the launcher have none of the plain class names of
portal.css. Each class of these pages has a rule in the mapped stylesheet. Eachforandhref="#..."points to an identifier of the page. - The mapped stylesheet and the mapped script have none of the plain names.
node --checkaccepts the mapped script, when the image hasnode. - Over 200 seeds, each page has the same canonical form. The mask inserts at most 3 elements, and the counts 0, 1, 2 and 3 all occur.
- The tests of the sign-in page read the mapped names from the mask. The tests of the anti-enumeration compare the canonical form.
A browser checks the look, not a unit test. tools/dev/ui-check.sh runs a Playwright check against a portal that you run. A check of this measure compares screenshots of a portal with the mask and of a portal without it. The viewports are 1280 and 390 pixels, in the dark and the light scheme, with and without script. A difference of one pixel is a failure.
The project does not use random names for the fields of the form (see measure 3). It does not change the class names at each render, because such a name cannot go into a file that the browser keeps. The structure changes at each render, and the names do not. The settings pages are not changed.
The box "Remember me"
The form has a box with the field name keep. The value of a ticked box is 1. The box is a part of the form for the anti-enumeration and the anti-bot checks. These rules apply:
- The server reads the field with the other fields, before it checks for an unknown field. The box never makes the form invalid. Only the value
1counts as ticked. Any other value is the same as no field. - A failed check of the form and a wrong password give the same answer, with the box ticked or not. The box changes only the session that a good sign-in opens. It does not change a refusal.
- The page after a refusal never shows the box ticked. The answer to a refusal therefore does not depend on what the client sent. The login and the password are not shown again either.
- The box has no script. The label holds the box, and its class goes through the mask like all other classes of the page. The mask never wraps a label that holds a field.
- The words of the label are the life of the session, for example
Stay signed in for 30 days. The label is the only text of the box: it has notitle, no hidden text and noaria-describedby. - The row of the box is one group, at the left edge of the fields. It is as wide as the group, so a click beside the group does not tick the box.
- With
session.remember = false, the page has no box. The server still reads the field and ignores its value. - The name
keepis a common word. It does not name the product.
The second step
With authentication.mfa other than off, an account can have a second factor (see Authentication and sessions and Security model). The five measures above stay the same. The second factor adds no measure to this list.
- Step 1 does not change. A wrong password, an unknown login and a failed check of the form give the same answer. An account with a second factor and an account without give the same refusal. The test
a_wrong_password_looks_the_same_for_an_account_with_and_without_a_second_factorcompares the canonical form and the headers. - Step 2 is for a person who knows the password. When the password is right and the account has a second factor, the answer is a card with a field for the code. A person who sees this card learns that the account has a second factor. This is accepted: the person has the password. A person without the password never reaches the card.
- The state is a token. The hidden field
pendingholds a token that the server signs. It holds the account, the box "Remember me", the count of wrong codes and the time. It also holds a keyed digest of the password and of the second factor of the account at the password step. - The token is bound. A new password, a reset of the second factor or a new superadmin credential refuses the token. The token is bound to the client binding and to the anti-CSRF token. It lives 5 minutes. Any instance with the session secret can check it. A damaged, old or foreign token gives the page "The page was open too long", with status 403.
- The routes. The routes are
POST /auth/login/codeandPOST /auth/login/enrol. They have the checks of the first step. These are theOrigincheck, the content type, the limit of the bodies read at the same time and the size of the body. ForwardAuth lets both paths pass without a session, as it does for/auth/login. - The cards go through the pass of the names. Their classes and identifiers are mapped like the classes of the sign-in card. They have no inline script and no inline style. A test checks that no plain class name is in the page. The copy button of the recovery codes finds its field from its place in the box, not from an identifier. The name map thus does not break it.
- Counters. Each code counts before the comparison, in the database row of the account and in the limiter of the address with the key
mfa:<address>. Five failed codes in 10 minutes lock the second step of the account for 5 minutes. A good code clears both counts. - Limits of the address. The limits of the address are the keys
security.login_attempts_per_ip,security.login_windowandsecurity.login_lockout. The metricportal_login_attempts_total{result="mfa_failure"}counts the wrong codes. They add to the refused sign-ins that the alerts of the portal read. The log linelogin_failedhasreason=mfa. - A good sign-in does not clear the password failures of the address. The failures can name other logins. They expire after
security.login_window. A good second step clears only the count of the second step of the address (the keymfa:<address>). A script that knows a password cannot clear the failures of the address. - A database without the second factor. The schema version 8 holds the tables of the second factor and the column
credentialofsessionswith no migration. A database without these objects stops the portal at start with a message that names them.
The look of the sign-in page
The sign-in page and the card of the second step have one look. It is a flat card, 320 px wide, with fields that have a label that moves up. The code is in src/ui/signin.rs. The rules are in web/portal.css. These rules are plain classes, and they go through the pass of measure 5.
- The band. A solid band at the top of the card shows the page that the visitor asked for. It has the word "Redirect" and then the path. The portal derives the path from the signed
rdof the page. - The band shows no host. The value
rdis a path, and the browser goes to it on the host of the sign-in page. The band shows the path for every destination, also for a page of the portal. A name would tell the pages of the product from the other paths. - The band is plain text. The band does not show the query. It shows a path of 96 characters at most, and the stylesheet cuts what does not fit. The band never has a link, whatever
rdholds. The code drops the control characters and the characters that change the order of text. The code escapes the rest. - No destination, no band. When
rdis the default/, the card has no band and starts with the fields. A page that has a band and a page that has none look the same in all other parts. - The band does not leak. The band depends on
rdonly. It does not depend on the login, on the password or on the cause of a refusal. The testa_refusal_with_a_destination_has_the_same_band_for_each_causecompares the refused pages. - The strip of the message. A message is a strip at the bottom edge of the card, under the button. The strip has the height (32 px), the width, the layout and the type of the band, in the colour of danger. The card clips it with its radius.
- The strip is optional. The page has the strip only when it has a message, so no empty place exists for it. A long message wraps, and the strip grows by whole lines. The strip is the last part of the card, after the button, and has
role="alert". - Invalid fields. A refused sign-in marks the two fields as invalid. A limit or an expired form does not mark them. Every cause of a refusal gives the same strip.
- The place of the fields. A card with a strip is higher than a card without one. The card has a top margin of 32 px for that case. The fields thus stay at the same place in the window when a refusal gives the page again. A message of two lines moves the fields up by 8 px.
- The label that moves up. The label is a real
<label for>. It moves up with:focus,:placeholder-shownand the autofill states. No script is needed. A browser that does not know:has()keeps the label up, so the label never covers the text. - The button that shows the password. The page has the button with the attribute
hidden. The shared script shows it, and it changes the type of the field. Without script, there is no button. The script finds the button by a data attribute that the pass maps. - The title. The title is always
Authentication. A hidden title element names the page:Authenticationfor the password step andVerificationfor the second step. - The browser check.
tools/dev/ui-check-login.jschecks the band, the labels, the button, the strip of the message, the targets, the contrast and the position of the card. It also runs a real sign-in, with and without a destination, and it checks the second step. The header of the file explains how to run it. - Other cards do not change. The 404, the denied page, the success page and the forced enrolment keep the card
card. None of the new rules applies to them.
Operation notes
- A new session secret changes the mapped names and the mapped paths. It also ends the sessions, so the effect is the same as the effect of an upgrade.
- An upgrade changes the hash in the asset paths. A page that an old instance served can ask for a file that a new instance does not have. During an upgrade of one instance at a time, this gives a page without style for a short time. A reload fixes it.
- A form that was open at an upgrade can give the page "The page was open too long" once. This happens when the upgrade changed the name of the cookie of the form.
- A script that uses
curlfor the sign-in must read the fieldtokenof the page. It must wait one second and then post the field.demo/lib.shdoes this. - The page changes the order of the attributes at each render. A script must read the attributes of a tag in any order. It must not use the plain class names or the identifiers of the page. Use the field names.
demo/lib.shandtools/dev/ui-check.jsdo this. tools/dev/ui-check.jswaits 1.2 seconds before it submits the form.
Source of this page: docs/design/login-hardening.md.