Summary
The OIDC authorization endpoint allows users with a TOTP-pending session (password verified, TOTP not yet completed) to obtain authorization codes. An attacker who knows a user's password but not their TOTP secret can obtain valid OIDC tokens, completely bypassing the second factor.
Details
When a user with TOTP enabled logs in at POST /api/user/login, the server creates a session with TotpPending: true and returns a session cookie. The context middleware (internal/middleware/contextmiddleware.go:56-66) correctly sets TotpPending: true and does not set IsLoggedIn for these sessions.
However, the OIDC authorize handler (internal/controller/oidccontroller.go:105-116) only checks whether a user context exists via utils.GetContext(c). It does not check IsLoggedIn or TotpPending. Since the context middleware populates a context for TOTP-pending sessions (with the username filled in), GetContext succeeds, and the handler proceeds to issue an authorization code at line 156 using the username from the incomplete session.
For comparison, the proxy controller (internal/controller/proxycontroller.go:176-179) correctly blocks TOTP-incomplete sessions by checking IsBasicAuth && TotpEnabled and setting IsLoggedIn = false. The OIDC authorize handler has no equivalent guard.
StoreCode at internal/service/oidcservice.go:305 saves the code with the victim's sub claim. The attacker then exchanges this code at POST /api/oidc/token for a valid access token and ID token.
PoC
Prerequisites: a tinyauth instance with at least one OIDC client configured and a local user with TOTP enabled.
Step 1 — Log in with password only (do not complete TOTP):
curl -c cookies.txt -X POST http://localhost:3000/api/user/login \ -H "Content-Type: application/json" \ -d '{"username":"totpuser","password":"totp123"}'
Response: {"message":"TOTP required","status":200,"totpPending":true}
Step 2 — Request an OIDC authorization code using the TOTP-pending cookie:
curl -b cookies.txt -X POST http://localhost:3000/api/oidc/authorize \ -H "Content-Type: application/json" \ -d '{"clientid":"my-client-id","redirecturi":"http://localhost:8080/callback","responsetype":"code","scope":"openid","state":"test"}'
Response: {"redirecturi":"http://localhost:8080/callback?code=<AUTHCODE>&state=test","status":200}
Step 3 — Exchange the code for tokens:
curl -X POST http://localhost:3000/api/oidc/token \ -u "my-client-id:my-client-secret" \ -d "granttype=authorizationcode&code=<AUTHCODE>&redirecturi=http://localhost:8080/callback"
Response contains accesstoken, idtoken, and refreshtoken for the victim user. TOTP was never submitted.
Impact
Complete bypass of TOTP/MFA for any user account on any tinyauth instance that has OIDC clients configured. An attacker who has compromised a user's password (credential stuffing, phishing, database breach) can obtain SSO tokens for that user's identity without knowing the TOTP secret. This defeats the purpose of the second factor entirely. All downstream applications relying on tinyauth's OIDC provider for authentication are affected.
Summary
The OIDC token endpoint does not verify that the client exchanging an authorization code is the same client the code was issued to. A malicious OIDC client operator can exchange another client's authorization code using their own client credentials, obtaining tokens for users who never authorized their application. This violates RFC 6749 Section 4.1.3.
Details
When an authorization code is created, StoreCode at internal/service/oidcservice.go:305-322 correctly stores the ClientID alongside the code hash in the database (line 316).
During token exchange at internal/controller/oidccontroller.go:267-309, the handler retrieves the code entry at line 268 and validates the redirecturi at line 291, but never compares entry.ClientID against the requesting client's ID (creds.ClientID). The code proceeds directly to GenerateAccessToken at line 299.
The developers clearly intended this check to exist, the refresh token flow at internal/service/oidcservice.go:508-510 has the exact guard: if entry.ClientID != reqClientId { return TokenResponse{}, ErrInvalidClient }. It was simply omitted from the authorization code grant.
The entry.ClientID field is stored in the database but never read during authorization code exchange.
PoC
Prerequisites: a tinyauth instance with two OIDC clients configured (Client A and Client B). Both clients must have at least one overlapping redirect URI, or the attacker must be able to intercept the authorization code from Client A's redirect (via referrer leak, browser history, log access, etc.).
Step 1 — Log in as a normal user:
curl -c cookies.txt -X POST http://localhost:3000/api/user/login \ -H "Content-Type: application/json" \ -d '{"username":"admin","password":"admin123"}'
Step 2 — Authorize with Client A:
curl -b cookies.txt -X POST http://localhost:3000/api/oidc/authorize \ -H "Content-Type: application/json" \ -d '{"clientid":"client-a-id","redirecturi":"http://localhost:8080/callback","responsetype":"code","scope":"openid","state":"test"}'
Extract the code parameter from the redirecturi in the response.
Step 3 — Exchange Client A's code using Client B's credentials:
curl -X POST http://localhost:3000/api/oidc/token \ -u "client-b-id:client-b-secret" \ -d "granttype=authorizationcode&code=<CODEFROMSTEP2>&redirecturi=http://localhost:8080/callback"
The server returns a valid accesstoken, idtoken, and refreshtoken. Client B has obtained tokens for a user who only authorized Client A.
Impact
A malicious OIDC relying party operator who can intercept or observe an authorization code issued to a different client can exchange it for tokens under their own client identity. This enables user impersonation across OIDC clients on the same tinyauth instance. The attack requires a multi-client deployment and a way to obtain the victim client's authorization code (which is passed as a URL query parameter and can leak through referrer headers, browser history, or server logs). Single-client deployments are not affected.