@@ -1032,6 +1032,11 @@ export const make = Effect.gen(function* () {
10321032 ) ;
10331033 } ;
10341034
1035+ // T3 Connect credential issuance, DPoP exchanges and device revocation take turns. Two mints
1036+ // at once would open two requests with one code, and a revoke landing between an exchange
1037+ // spending its credential and trusting the key would be undone by that exchange.
1038+ const connectTrustLock = yield * Semaphore . make ( 1 ) ;
1039+
10351040 const exchangeBootstrapCredentialForAccessToken : EnvironmentAuth [ "Service" ] [ "exchangeBootstrapCredentialForAccessToken" ] =
10361041 ( credential , requestedScopes , requestMetadata , input ) => {
10371042 return resolveBootstrapGrant ( credential , {
@@ -1100,6 +1105,8 @@ export const make = Effect.gen(function* () {
11001105 ) ,
11011106 ) ,
11021107 ) ,
1108+ ( exchange ) =>
1109+ input ?. proofKeyThumbprint ? connectTrustLock . withPermits ( 1 ) ( exchange ) : exchange ,
11031110 Effect . withSpan ( "EnvironmentAuth.exchangeBootstrapCredentialForAccessToken" ) ,
11041111 ) ;
11051112 } ;
@@ -1184,14 +1191,11 @@ export const make = Effect.gen(function* () {
11841191 . recordConnectRequestClient ( pairingLinkId , client )
11851192 . pipe ( Effect . mapError ( ( cause ) => new ServerAuthConnectDevicesError ( { cause } ) ) ) ;
11861193
1187- // Finding a device's open request and creating one must not interleave, or two mints at
1188- // once would leave two requests with the same code.
1189- const connectIssueLock = yield * Semaphore . make ( 1 ) ;
11901194 const issueConnectCredential : EnvironmentAuth [ "Service" ] [ "issueConnectCredential" ] = Effect . fn (
11911195 "EnvironmentAuth.issueConnectCredential" ,
11921196 ) ( function * ( { proofKeyThumbprint, requireApproval } ) {
11931197 return yield * issueConnectCredentialLocked ( { proofKeyThumbprint, requireApproval } ) . pipe (
1194- connectIssueLock . withPermits ( 1 ) ,
1198+ connectTrustLock . withPermits ( 1 ) ,
11951199 ) ;
11961200 } ) ;
11971201 // Untraced: the issueConnectCredential span above already covers it.
@@ -1257,13 +1261,15 @@ export const make = Effect.gen(function* () {
12571261 const revokeConnectDevice : EnvironmentAuth [ "Service" ] [ "revokeConnectDevice" ] = Effect . fn (
12581262 "EnvironmentAuth.revokeConnectDevice" ,
12591263 ) ( function * ( proofKeyThumbprint ) {
1260- const removed = yield * bootstrapCredentials
1261- . revokeConnectDevice ( proofKeyThumbprint )
1262- . pipe ( Effect . mapError ( ( cause ) => new ServerAuthConnectDevicesError ( { cause } ) ) ) ;
1263- const revokedSessions = yield * sessions
1264- . revokeByProofKey ( proofKeyThumbprint )
1265- . pipe ( Effect . mapError ( ( cause ) => new ServerAuthSessionRevocationError ( { cause } ) ) ) ;
1266- return removed || revokedSessions > 0 ;
1264+ return yield * Effect . gen ( function * ( ) {
1265+ const removed = yield * bootstrapCredentials
1266+ . revokeConnectDevice ( proofKeyThumbprint )
1267+ . pipe ( Effect . mapError ( ( cause ) => new ServerAuthConnectDevicesError ( { cause } ) ) ) ;
1268+ const revokedSessions = yield * sessions
1269+ . revokeByProofKey ( proofKeyThumbprint )
1270+ . pipe ( Effect . mapError ( ( cause ) => new ServerAuthSessionRevocationError ( { cause } ) ) ) ;
1271+ return removed || revokedSessions > 0 ;
1272+ } ) . pipe ( connectTrustLock . withPermits ( 1 ) ) ;
12671273 } ) ;
12681274
12691275 const revokeConnectDeviceByCode : EnvironmentAuth [ "Service" ] [ "revokeConnectDeviceByCode" ] =
@@ -1410,10 +1416,12 @@ export const make = Effect.gen(function* () {
14101416 const currentProofKey = yield * sessions
14111417 . proofKeyThumbprintOf ( currentSessionId )
14121418 . pipe ( Effect . mapError ( ( cause ) => new ServerAuthOtherSessionsRevocationError ( { cause } ) ) ) ;
1413- yield * bootstrapCredentials
1414- . revokeConnectDevicesExcept ( Option . getOrNull ( currentProofKey ) )
1415- . pipe ( Effect . mapError ( ( cause ) => new ServerAuthConnectDevicesError ( { cause } ) ) ) ;
1416- return yield * revokeOtherSessionsExcept ( currentSessionId ) ;
1419+ return yield * Effect . gen ( function * ( ) {
1420+ yield * bootstrapCredentials
1421+ . revokeConnectDevicesExcept ( Option . getOrNull ( currentProofKey ) )
1422+ . pipe ( Effect . mapError ( ( cause ) => new ServerAuthConnectDevicesError ( { cause } ) ) ) ;
1423+ return yield * revokeOtherSessionsExcept ( currentSessionId ) ;
1424+ } ) . pipe ( connectTrustLock . withPermits ( 1 ) ) ;
14171425 } ) ;
14181426
14191427 const issueStartupPairingUrl : EnvironmentAuth [ "Service" ] [ "issueStartupPairingUrl" ] = ( baseUrl ) =>
0 commit comments