mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
fix(oauth): bind an authorization code to the session that consented, not to the password version
Reading the password version from the oauth domain meant injecting the users repository, which the auth domain owns. The sessions domain answers the same question and more: a password reset or change ends every session of the user, and a sign-out ends the one that consented. The code now carries that session's id and both token endpoints issue tokens for it only while the session is active, checked in the transaction that writes them. A token from before sessions were tracked has no session to check and passes, as it does everywhere until it expires. A refused code is audited as session_ended.
This commit is contained in:
@@ -264,7 +264,7 @@ describe('GET /oauth/authorize — SDK authorizationHandler over trekOAuthProvid
|
||||
// SDK-side exchange see it.
|
||||
const code = await withRequestContext(orm, () =>
|
||||
containerSideOauth.createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://client.example.com/cb',
|
||||
|
||||
@@ -332,7 +332,7 @@ describe('POST /oauth/token — authorization_code grant', () => {
|
||||
|
||||
// Create code for client1
|
||||
const code = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: r1.client!.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app1.example.com/cb',
|
||||
@@ -361,7 +361,7 @@ describe('POST /oauth/token — authorization_code grant', () => {
|
||||
const { verifier, challenge } = makePkce();
|
||||
|
||||
const code = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: r.client!.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
@@ -389,7 +389,7 @@ describe('POST /oauth/token — authorization_code grant', () => {
|
||||
const { verifier, challenge } = makePkce();
|
||||
|
||||
const code = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: r.client!.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
@@ -417,7 +417,7 @@ describe('POST /oauth/token — authorization_code grant', () => {
|
||||
const { challenge } = makePkce();
|
||||
|
||||
const code = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: r.client!.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
@@ -445,7 +445,7 @@ describe('POST /oauth/token — authorization_code grant', () => {
|
||||
const { verifier, challenge } = makePkce();
|
||||
|
||||
const code = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: r.client!.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
@@ -505,7 +505,7 @@ describe('POST /oauth/token — refresh_token grant', () => {
|
||||
const { verifier, challenge } = makePkce();
|
||||
|
||||
const code = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: r.client!.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
@@ -592,7 +592,7 @@ describe('POST /oauth/revoke', () => {
|
||||
const { verifier, challenge } = makePkce();
|
||||
|
||||
const code = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: r.client!.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
@@ -1066,7 +1066,7 @@ describe('Sessions — /api/oauth/sessions', () => {
|
||||
const { verifier, challenge } = makePkce();
|
||||
|
||||
const code = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: r.client!.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
@@ -1115,7 +1115,7 @@ describe('Sessions — /api/oauth/sessions', () => {
|
||||
if (!client) throw new Error('the OAuth client was not created');
|
||||
const { verifier, challenge } = makePkce();
|
||||
const code = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: client.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
@@ -1210,7 +1210,7 @@ describe('H1 — PKCE format validation', () => {
|
||||
const { challenge } = makePkce();
|
||||
|
||||
const code = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: r.client!.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
@@ -1265,7 +1265,7 @@ describe('H5 — All invalid_grant cases return identical response body', () =>
|
||||
const { verifier, challenge } = makePkce();
|
||||
|
||||
const code = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: r.client!.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
@@ -1287,7 +1287,7 @@ describe('H5 — All invalid_grant cases return identical response body', () =>
|
||||
|
||||
// Redirect URI mismatch (need fresh code since code is single-use)
|
||||
const code2 = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: r.client!.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
@@ -1418,7 +1418,7 @@ describe('C3 — Refresh token replay detection', () => {
|
||||
const { verifier, challenge } = makePkce();
|
||||
|
||||
const code = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: r.client!.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
@@ -1467,7 +1467,7 @@ describe('C3 — Refresh token replay detection', () => {
|
||||
const { verifier, challenge } = makePkce();
|
||||
|
||||
const code = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: r.client!.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
@@ -1509,7 +1509,7 @@ describe('C3 — Refresh token replay detection', () => {
|
||||
const { verifier, challenge } = makePkce();
|
||||
|
||||
const code = await createAuthCode({
|
||||
passwordVersion: 0,
|
||||
sessionId: null,
|
||||
clientId: r.client!.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
|
||||
Reference in New Issue
Block a user