Skip to content

Correct the README, doc comments and example against the code - #341

Merged
umputun merged 7 commits into
masterfrom
audit-docs-fixes
Nov 25, 2026
Merged

umputun merged 7 commits into
masterfrom
audit-docs-fixes

Conversation

@paskal

@paskal paskal commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Previously, the README named middleware, options and interface signatures that do not exist, several of its Go examples did not compile, its line anchors into the code had drifted, and many provider limits and requirements were not written down. It also did not say that the v1 module carries an unfixed golang-jwt advisory. After this change, the README, the doc comments, AGENTS.md and the example describe what the code does, and the changed Go code blocks compile against v2.

Fixes:

  • Security: the README states that v1 still depends on github.com/golang-jwt/jwt v3, which has GO-2025-3553 (excessive memory allocation during header parsing) with no fixed v3 release, that v1 gets security fixes where its dependencies allow, and that v1 users should move to v2.
  • Middleware: the section names the Authenticator methods Auth, AdminOnly, Trace and RBAC under the /v2 import path; middleware.Admin does not exist. A token is accepted when the provider name signed into it, or its user id prefix, names a registered provider.
  • Examples that did not compile now do: devAuthServer.Run(context.Background()), the GetEmailFn example, which also checked err too late, the basic auth example, and the email and Telegram examples, which use logger.Std. The direct provider's JSON body example, in the README and the LoginHandler doc comment, loses a trailing comma that made it answer 400.
  • Avatars: the BoltDB URI is bolt:///tmp/avatars.bdb (the old one opened a relative path), the Mongo URI example is corrected, the avatar link example uses a valid id, AvatarStore is documented as optional with what nil and avatar.NoOp do, and the size, format and identicon size limits are listed.
  • Tokens: SecretReader.Get returns (string, error), per-site secrets need Opts.AudSecrets, and ClaimsUpdater is also called with a nil claims.User. The audience check is Opts.AudienceReader, one allowlist for the whole service. The token and cookie lifetimes default to 15 minutes and 31 days; a Telegram login sets its own 30-minute token expiry, and reissuing a persistent cookie on a refresh starts its full CookieDuration again.
  • Requests: query and header tokens take precedence over the cookie and skip the XSRF check, /auth/user and /auth/status report the identity Auth would accept, every logout path is served by the provider added first, and the XSRF section lists every route and middleware the check runs in and says XSRFIgnoreMethods entries are upper case.
  • Direct and verify providers: their responses and user ids, the fixed 30-minute confirmation token, the html/template message template with an example confirmation link, the empty user and address and malformed address checks the library makes, and the validation and rate limiting left to the application, and the replay protection a hand-built VerifyHandler lacks.
  • Telegram: the request lifetime, the need for a running Run or ProcessUpdate and the update format ProcessUpdate expects, the single-instance limit and the persistent cookie.
  • Dev provider and custom server: the dev provider's Host, its /auth mount, its bare user ids and the host the application must be opened on; the custom server's required logger, its optional login page options, its UserAuthorizationHandler and the ids it returns; custom provider names have to be path-safe; BearerTokenHookFn, ContextSender, NewTelegramAPIWithBaseURL and the CSP on custom handlers.
  • Provider setup: Apple's return URL is https://<your domain>/auth/apple/callback and its name arrives only on the first authorisation; the effect of SameSiteCookie on callbacks, Battle.net's EU endpoints, Patreon's paid subscriber flag and Microsoft avatars needing the avatar proxy are documented; NewTwitter is documented as an OAuth 1.0a provider.
  • Links into the code go to pkg.go.dev symbols or to files without line anchors.
  • AGENTS.md: a gofmt/goimports formatting row, verify tokens are one-shot within one Service by default, and the test-port note lists the fixed ports in use.

Behaviour changes, in the example only:

  • The example's Validator admits users of every provider the example registers. Previously, Twitter, Apple, Bitbucket, anonymous, email and Telegram logins succeeded and then got 401 on /private_data.
  • The example frontend passes the audience in the parameter each handler reads (site, or aud for the anonymous direct provider). Previously, it sent id, which nothing reads, so every token of the example had an empty audience.

Housekeeping: the finished backlog entry about the dev provider host is removed.

The changed README Go code blocks compile and pass go vet against v2 in a scratch module; on master the same check stops at the basic auth example. Tests pass with -race in both modules, the example builds, go mod tidy leaves no change, and golangci-lint v2.15.0 reports no issues in the root module and v2. No library code changes apart from doc comments.

A v2 release is due after this is merged: master carries the fixes of #340, #338 and #339 and the OAuth 2.0 provider for X, none of them in a release since v2.5.0 (released 19 November 2026).

@paskal
paskal requested a review from umputun as a code owner November 23, 2026 18:40
@coveralls

coveralls commented Nov 23, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 45624553093

Coverage decreased (-0.05%) to 88.549%

Details

  • Coverage decreased (-0.05%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 2 coverage regressions across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

2 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
v2/provider/telegram.go 2 89.6%

Coverage Stats

Coverage Status
Relevant Lines: 4113
Covered Lines: 3642
Line Coverage: 88.55%
Coverage Strength: 15.92 hits per line

💛 - Coveralls

The README named middleware, options and interface signatures that do
not exist, several of its Go examples did not compile, its line anchors
into the code had drifted, and many provider limits and requirements
were not written down. It also did not say that the v1 module depends
on golang-jwt/jwt v3, which has an advisory with no fixed v3 release.

The example's Validator rejected users of six of the providers it
registers, and its frontend sent the audience in a parameter no handler
reads, so every example token had an empty audience.
Version updates are switched off, so only security updates open pull
requests. v1.29.0 was published seconds after v2.5.0 and took the
"Latest" mark, so AGENTS.md now says to publish v1 first when both lines
are released together.
The verify message template now gets the service URL and a second
token meant for a link, so the example uses them instead of a fixed
host and the token meant for pasting.

@umputun umputun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the docs part is good to go after a few small corrections, and the Dependabot file should go.

  • README.md:174 - "accepts tokens only from providers registered on this service" is too strong. isProviderAllowed also accepts a token when the user id up to its first _ (the whole id when it has none) names a registered provider, whatever AuthProvider.Name says, so a service registering only bitbucket accepts bitbucket_dev tokens. Fix: say the provider is matched by the signed provider name or by that id prefix.
  • README.md:604-615 - the new two-site AudienceReader example sits under a section that promises one customer's tokens can't be used in another customer's subsystem. The reader is one allowlist for the whole service, so a site1 token passes on site2 routes. Fix: one sentence that the list is service-wide and a per-tenant route has to compare User.Audience with the tenant the request names.
  • README.md:716 - TokenDuration is not the lifetime of every JWT. A Telegram login sets ExpiresAt to 30 minutes (provider/telegram.go:343, same in v2) and Set keeps an explicit expiry, so the first Telegram token lives 30 minutes even with the example's one-minute TokenDuration. Fix: say it applies to tokens issued without an explicit expiry and mention the Telegram case.
  • _example/README.md:11 - "each provider below is enabled by its environment variables" reads as "set these and login works". Apple can't complete a login at the example's http://localhost:8080 (https only, no localhost, and form_post needs SameSiteNoneMode with SecureCookies), and X rejects localhost per the README's own X section. Fix: say the variables configure credentials and add one sentence for Apple and X.
  • AGENTS.md:49 - "The dev and custom server provider tests take their ports from the kernel" is true only after #340. On this branch they bind 8080, 9096, 18084 and 18085, and the port list leaves out 8080, 9096 and 18085. Fix: drop the sentence and list those ports, or leave it as is if #340 goes in first.
  • AGENTS.md:13 - pls keep the ~/.claude/format.sh row. Adding the gofmt/goimports row next to it is fine.
  • AGENTS.md:41 - pls drop the "Releases" section. The release order is mine to set, and if v2 should show as Latest I'll mark it directly.
  • .github/dependabot.yml - pls drop it. The repo never had a config, so version updates were never on, and the Dependabot PRs in history for /, /v2 and /_example were security updates from the repo settings, which open-pull-requests-limit doesn't cover. The file changes nothing, and its first lines are GitHub's "get started with version updates" template.

The middleware also accepts a token whose user id prefix names a
registered provider, the audience allowlist is shared by every tenant of
a service, and a Telegram login sets its own 30-minute expiry, so the
README claimed more than the code does. The example README read as if
setting the variables was enough for Apple and X, which cannot complete
a login on the example's localhost URL. The format.sh row stays in
AGENTS.md next to the new one.
The repository never had version updates enabled, and the security
updates it receives come from the repository settings, which the file
does not affect. Release order is the maintainer's call.
@paskal

paskal commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

All points are addressed in b118b19 and da1b578:

  • README.md:174: the provider is now described as matched by the signed provider name or by the user id up to its first _, with the bitbucket / bitbucket_dev case.
  • Multi-tenant section: the list is service-wide, and a per-tenant route has to compare User.Audience with the tenant the request names.
  • Token lifetime: TokenDuration applies to tokens issued without an explicit expiry, and a Telegram login sets its own 30-minute expiry.
  • _example/README.md: the variables configure credentials, and Apple and X are noted as unable to complete a login at http://localhost:8080.
  • AGENTS.md: the ~/.claude/format.sh row is back next to the gofmt/goimports row, and the "Releases" section and .github/dependabot.yml are removed (da1b578). The test-port sentence stays as it is, since Check user routes like Auth, clear rejected cookies, fix provider edge cases #340 is to be merged first.

@paskal
paskal requested a review from umputun November 24, 2026 18:00
The user and status routes now report the identity Auth accepts, basic
credentials included, with a fixed 401 body, and the verify provider
refuses an empty user or address and an address that would move the
user::address split, so the README described the routes and checks as
they were. The custom server snippet passed a logger the quick starts
never set, and Run panics on a nil one. A refresh gives a persistent
cookie its full CookieDuration again, so the option limits idle time.
LoginAuth no longer names outlook.com, which accepts only OAuth2 for
SMTP, SameSite Strict is scoped to providers on another site, and
provider names have to be path-safe or are skipped.
A persistent cookie gets its full CookieDuration again whenever a
refresh reissues it, so the quick-start comments now say the cookie
expires a day after it was last issued.

@umputun umputun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all points from the last round are fixed, thx. #340 is merged now, and two sentences here describe the routes as they were before it, plus a few smaller corrections:

  • README.md:189 - "Without a valid token /auth/user answers 401 with {"error": "..."} ... With one, /auth/user answers the token.User JSON" is not what #340 does. Basic credentials accepted by AdminPasswd or BasicAuthChecker get 200 with that identity and no token, a valid token rejected by the Validator or the provider check gets 401 and its cookie cleared, and the 401 body is always {"error":"unauthorized"}. It also contradicts the #340 line a few lines above it. Fix: say the routes report the identity Auth would accept, and answer 401 {"error":"unauthorized"} / "not logged in" otherwise.
  • README.md:311 - "The library does not check the format of address" is no longer true: after #340 sendConfirmation answers 400 invalid address for an address that contains :: or starts with :, and 400 for an empty user or address. Pls name those checks and keep the validate and rate-limit advice.
  • README.md:497-505 - the rewritten CustomServerOpt list leaves out L, and the snippet passes options.Logger, which neither quick start sets. CustomServer.Run calls Logf before it opens the listener, so a copy of this snippet panics on a nil logger at startup. Fix: mark L as required and use logger.Std in the snippet.
  • README.md:718 - add that reissuing the cookie resets its full CookieDuration. Each refresh reissues it, so CookieDuration limits idle time, not session age, and the quick-start comments promising re-login after a day read wrong without it.
  • README.md:376 - personal outlook.com mailboxes accept only OAuth2 for SMTP since September 2024 (Microsoft), and the sender has no OAuth2. Pls describe LoginAuth as LOGIN for servers that offer only LOGIN, e.g. Office 365 while the tenant allows basic SMTP auth, and drop outlook.com.
  • README.md:766 - "http.SameSiteStrictMode breaks every provider" is too broad. Strict only drops the handshake cookie on a cross-site callback, so a provider on the same site, like the dev server on the app's host, still works. Pls scope it to providers on another site.
  • README.md:463 and :514 - "any name is allowed" is not true. addProvider skips a name that fails isValidProviderName (spaces, reserved characters) and only logs an [ERROR] line, so the provider never shows up in /auth/list. Pls say the name has to be path-safe: letters, digits, -, ., _, ~.

@paskal

paskal commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

All points are addressed in 7a10c91, and the cookie lifetime in db6d847:

  • README.md:189: /auth/user and /auth/status report the identity Auth would accept, basic credentials included; otherwise /auth/user answers 401 {"error":"unauthorized"} and /auth/status "not logged in".
  • README.md:311: names the 400 for an empty user or address and the 400 invalid address for :: or a leading :; the validate and rate-limit advice stays.
  • Custom server: L is listed as required, and the snippet uses logger.Std; it passes go vet against master's v2.
  • Token lifetime: reissuing a persistent cookie on a refresh starts its full CookieDuration again, so it limits idle time, not session age; the quick-start comments say the cookie expires a day after it was last issued.
  • LoginAuth: LOGIN for servers that offer only LOGIN, e.g. Office 365 while the tenant allows basic SMTP auth; outlook.com is dropped.
  • SameSiteStrictMode is scoped to providers on another site, with the dev server on the application's host as the same-site case. Both Name lines require a path-safe name (letters, digits, -, ., _, ~), and the first says other names are skipped with an [ERROR] line.

@paskal
paskal requested a review from umputun November 25, 2026 07:48
umputun added a commit that referenced this pull request Nov 25, 2026
…in by id

A cookie token whose refresh fails went through JWTService.Reset directly, which sets
Content-Type text/plain, so under Trace a page that leaves the type to sniffing was
served as text/plain. The refresh-failure branch now uses resetCookies like the
Validator and provider rejections, in both modules. Only a cookie token reaches the
refresh, so the cookies are expired as before.

The example granted admin to any user named dev_admin, which an anonymous or email
login can pick. It now matches the id, which only the dev provider leaves unprefixed.

The godoc of Opts.VerifConfirmationStore and NewInMemoryVerifStore says a restart
forgets redeemed tokens. The same note for the README and AGENTS.md waits in
docs/backlog until #341 is merged, since it rewrites the lines next to both.

@umputun umputun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@umputun
umputun merged commit de305a3 into master Nov 25, 2026
7 of 9 checks passed
@umputun
umputun deleted the audit-docs-fixes branch November 25, 2026 17:16
umputun added a commit that referenced this pull request Nov 25, 2026
The example's Validator matched user id prefixes before the dev name
check. Dev ids are the bare typed names, so a dev user named
email_alice or custom123_x passed the dev_ rule. The signed provider
name now decides first. The bitbucket endpoint comes from
golang.org/x/oauth2/bitbucket, the same URLs, which gosec read as
hardcoded credentials.

README and example README fixes:
- a dev user without the dev_ prefix gets 401 and cleared cookies on
  the first authenticated request, not only on /private_data
- User.Audience is filled by Get, not by Parse or the login response
- TokenDuration applies to tokens issued through Set; a token signed
  with TokenService().Token gets no expiry unless ExpiresAt is set
- the default custom server login page also asks for a password
- an empty Telegram base URL selects the public API
- the service's own hostname accepts any port even when Opts.URL names
  one
- the reverse proxy case is labelled as not supported
- a restart forgets redeemed verify tokens with the default in-memory
  store, in the README and AGENTS.md, which closes that backlog item

The Opts.AudienceReader comment in both modules says nil allows any
audience and an empty list rejects every token, as checkAuds does.

New backlog items: aud from the login request is not proof of tenant
membership, a self-built handler must set claims.ID for the XSRF
check, and the LoginAuth comment still names outlook.com.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants