Changes in 0.2.0:
WARNING: HTTP Basic authentication is now off by default. Until now every app accepted an Authorization: Basic header with an ASF id and password, which is a way round the multi-factor authentication of an OAuth login. An app that depends on it must pass basic_auth=True to asfquart.construct() and have the LDAP libraries installed (asfquart[aioldap]). See “HTTP Basic authentication” in docs/sessions.md.
Everybody is logged out once by this upgrade. The session cookie is now called __Host-session, and a cookie under the old name, session, is no longer read. An app that sets SESSION_COOKIE_DOMAIN or SESSION_COOKIE_PATH, or is served from a path (APPLICATION_ROOT), or turns SESSION_COOKIE_SECURE off, must stop, or set a SESSION_COOKIE_NAME of its own: a browser refuses a __Host- cookie with any of those, and such an app now fails to start, with an error that names the setting. See “Cookie names” in docs/sessions.md.
Sessions
__Host- prefix: __Host-session and __Host-asfquart-oauth-state. A browser accepts such a cookie only from the host itself, over HTTPS, so a page on another host of the same site can no longer give a visitor's browser a session or a login of its own. The login cookie now has Path=/, which the prefix requires, where it had the path of the OAuth endpoint.app.sessions to an async store (with create, validate and destroy methods, and optionally replace or register) and the cookie then carries only a session id. Use the new session.awrite(), session.aclear() and session.areplace() with such a store; the sync write() and clear() raise when one is configured. The interface is documented in docs/session-stores.md.session.areplace() refuses a session object with no uid attribute, such as a plain dict, with a TypeError. The user's existing session is left alone.MAX_SESSION_AGE config option (seconds) ends a session that many seconds after it was created, regardless of activity. It defaults to 7 days, which is when sessions ended before as well, because of the next point. Set it to 0 for no limit.MAX_SESSION_IDLE option (default 7 days), which auth.require then uses. It has an effect when it is less than MAX_SESSION_AGE.session.write() and awrite() keep the creation time of the session of the user who is logged in, so changing a session does not extend its maximum lifetime. Pass new_session=True after authenticating a user.apptoken.txt) is no longer used as the application secret, which left the app unable to write a session. It is treated as missing: a new secret is generated and saved. The application secret is now documented, in docs/app-secret.md (#75).OAuth
Sec-Fetch-Site check as light CSRF protection; a POST logout answers 204.docs/oauth.md (#69):Sec-Fetch-Site: same-origin) and is a 403 from anywhere else. A request without the header, as from a client that is not a browser, is let through.POST logout from another host of the same site, which was accepted. Allow it with the new logout_same_site argument of setup_oauth, or generics.OAUTH_LOGOUT_SAME_SITE = True.GET logout must also be a navigation in a window or tab (Sec-Fetch-Mode: navigate, Sec-Fetch-Dest: document) and not a prefetch. A logout link in the app, a typed address and a bookmark still work.GET logout logs a warning, once, that logout should be a POST. Turn GET logout off with the new logout_by_get argument of setup_oauth, or generics.OAUTH_LOGOUT_BY_GET = False; it is then a 405.login redirect target may not be the OAuth endpoint itself, and is a 400: /auth?login=/auth?logout would get round these checks.login and logout redirect targets must be local paths (start with /, not //), and may not contain a backslash or control characters: browsers read /\example.org as //example.org, and the login target is sent in a Refresh header. A target may be at most 2,048 characters (generics.MAX_REDIRECT_URI_LENGTH). Anything else is a 400 (#90, #124).docs/oauth.md.setup_oauth takes a callback_host argument, to pin the host of the OAuth callback URL instead of taking it from the request's Host header. Its default is the new generics.OAUTH_CALLBACK_HOST, which is unset (#93).generics.DEFAULT_MAX_PENDING_LOGINS (10,000) are kept, the oldest being dropped first. setup_oauth takes a max_pending_logins argument. A warning says how many were dropped (#99, #95).POST body rather than the URL of a GET, so it stays out of access logs. generics.OAUTH_URL_CALLBACK no longer takes a %s. A value that still has one is sent as a GET with a warning - except the old default, which gets the POST. Redirects from the provider aren't followed (#96).Referrer-Policy: no-referrer.? from an empty query string is dropped.uid in the form of an ASF user id (generics.OAUTH_UID_RE); anything else is a 403 (#132).origin_uri must be the callback address of this login, with the same state. A code that the provider issued for a login at another app, or for another login at this one, is refused with a 403. The provider does not tie a code to the app that presents it, so such a code would otherwise have logged its holder in as somebody else. A response without origin_uri is accepted, with a warning logged once. Set callback_host (or generics.OAUTH_CALLBACK_HOST): without it the callback address comes from the Host header of the request, which a client chooses, and the check can be got round unless the proxy refuses such requests. A warning is logged once when a login is started without it. A login started with a Host header too long for a callback address is now a 400.generics.OAUTH_TIMEOUT). A provider that cannot be reached or is too slow is a 403 rather than a 500 (#130).docs/oauth.md (#91).Clear-Site-Data header so the browser drops its cache, cookies and storage.Authorization, tokens and LDAP
auth.require accepts the classmethods of a Requirements subclass, so an app can add its own requirements next to the built-in ones (#41).
auth.require no longer drops its first argument when all_of is given as well: the two are combined. Anything that is not a requirement is a TypeError when the endpoint is defined, and auth.requirements_to_iter is deprecated (#43, #45).
auth.Requirements.mfa_enabled is now mfa_protected. The old name still works (#44).
Requirements work with any session object that has the attributes they read, not only a ClientSession - with a session store it may be something else. The attributes are listed in session.SessionProtocol, and auth.require raises a TypeError naming the attribute if a session is missing one (#44).
The session attributes isMember, isChair, isRoot and isRole are now is_member, is_chair, is_root and is_role. The old names still work, with a DeprecationWarning, on a ClientSession and on a session store's own class. A ClientSession's dictionary keys keep the old names, so what /auth returns is unchanged.
HTTP Basic authentication is off by default (see the warning above), and is turned on with the new basic_auth argument of construct(). When it is off, an Authorization: Basic header is a 401 Basic authentication is not enabled, and LDAP is not contacted. basic_auth=True without the LDAP libraries is a RuntimeError when the app is constructed; before, Basic authentication then did nothing, without saying so.
A username for basic authentication must have the form of an ASF user id, and the password may not be empty; otherwise the request is a 403 and LDAP is not contacted (#128).
The rule for the form of an ASF user id is written in one place, base.ASF_UID_RE. generics.OAUTH_UID_RE and ldap.VALID_UID_RE are that same pattern.
The cache of LDAP lookups no longer keeps expired entries: they are removed whenever a lookup is made, and the cache holds at most ldap.DEFAULT_LDAP_CACHE_MAX_ENTRIES (1,000) users, the least recently used lookup being dropped first (#95).
A bearer token presented when no token_handler is registered is no longer printed to stdout; a warning without the token is logged instead (#85).
A Bearer header with no token in it, such as Bearer a=b or a bare Bearer, is no session, and the token_handler is not called. It was called with None or an empty string.
/auth raises a TypeError naming the class when a session store's session is neither a dictionary nor has model_dump(). It was an error from quart that did not say why.
An Authorization header that does not parse no longer causes an error.
A password that LDAP refuses for HTTP Basic authentication is logged as a warning, with the user id and without the password, at most once a minute for one user and with a count of the failures in between, and at most 60 such lines a minute for all users together, with a count of the rest. Until now a wrong password left no trace. The 403 response no longer includes the error text from LDAP, which goes to the log instead, and an unexpected LDAP error is logged, not printed. See “Failed logins” in docs/sessions.md.
A request waits for LDAP for at most 30 seconds (ldap.LDAP_TIMEOUT), and at most 10 LDAP checks go on at one time (ldap.MAX_LDAP_OPERATIONS), counting those that a request has stopped waiting for. Until now there was no limit on either, so an LDAP server that did not answer held a thread and a connection for every request with HTTP Basic authentication. A request that finds 10 going on waits for one to end, within its 30 seconds, and at most 100 wait like that (ldap.MAX_LDAP_WAITING). When the time is up, or 100 are waiting, the request is a 500, as it is when LDAP cannot be reached. An LDAP check is not retried. See “LDAP” in docs/external-services.md.
An LDAP server that does not answer the connection itself stops the whole application, and not only the request that asked, for as long as the connection is attempted: the LDAP library holds the Python interpreter meanwhile. Until now that had no end. It now ends after 5 seconds (ldap.LDAP_NETWORK_TIMEOUT) for each LDAP check, with a 500. asfquart does this by setting LDAPNETWORK_TIMEOUT in the environment of the process in construct(basic_auth=True), unless it is already set; programs that the application starts afterwards inherit it. Connections to LDAP are now made one at a time, which the timeout needs with asfpy 0.60 and earlier; the lookups that follow a connection still go on side by side.
Requests and responses
utils.formdata() refuses a form larger than the new MAX_FORM_CONTENT_LENGTH config option (default 100 KB) with a 413, before the form is parsed. The limit is separate from quart's MAX_CONTENT_LENGTH, and the lower of the two applies. A request without a Content-Length header is no longer a 500. See docs/forms.md (#131).utils.formdata() answers a JSON body that is not an object (a list, a string, a number, null) with a 400. It was a 500, and a few such values, a list of pairs for one, were taken to be fields.use_template passes a Response returned by the handler (a redirect, say) through untouched, instead of handing it to the template as the data dictionary.text/plain; charset=utf-8.ValueError, a failed OAuth exchange is a 403, a non-callable token_handler raises TypeError.Documentation
Requirements.committer is documented as what it is: it passes for any session, which at the ASF means a committer, and it does not look at projects or tell a role account from a person. docs/auth.md says so, with an example of a requirement of one's own for an app that needs more. Its behaviour has not changed.docs/limits.md, #127). Its tables of values are compared with the code by the tests.docs/external-services.md, #129), and why an application runs as one process (docs/one-process.md, #160).docs/input-validation.md, #125). Its tables of values and examples are compared with the code by the tests.docs/reverse-proxy.md): asfquart does not send a Strict-Transport-Security header, which is for the proxy to set, and what else the proxy has to do.Other
import asfquart now imports asfquart.auth as well.run() prints an https:// URL when a certfile is given.exceptiongroup backport is no longer a dependency (#81).py.typed marker, so an app‘s type checker now reads asfquart’s own annotations. It is checked with pyright in CI. What an app's checker may newly report:session.read() returns a SessionProtocol or None. Reading fullname, email or projects needs an isinstance(session, ClientSession) first.asfquart.APP is typed as a QuartApp, though it is None until construct() is called. Code that also runs where there is no app calls asfquart.app_or_none(), which is new and is typed as QuartApp | None.auth.require and use_template keep the signature of the endpoint they decorate, so a call to it with the wrong arguments is now seen.auth.Requirement and base.TokenHandler.uv_build backend, uv.lock); tests run on pytest 9 with pytest-asyncio 1.x; Dependabot keeps dependencies and GitHub Actions current.Changes in 0.1.12:
quart>=0.20.0,<1, asfpy>=0.56,<1, and caret ranges for ezt, easydict and watchfiles. No code changes.Changes in 0.1.11:
token_file when constructing a QuartApp to control if / where the app secret shall be stored.Changes in 0.1.10:
Changes in 0.1.9:
metadata dict to session objects where apps can store session-specific instructionsasyncinotify to watchfiles to allow for functionality on other platforms, such as macOSChanges in 0.1.8:
Changes in 0.1.7:
Changes in 0.1.6: