@@ -186,8 +186,10 @@ function writeRefreshIntent(refreshToken: string, status: RefreshIntentStatus):
186186 // failure so the caller can fail closed instead of refreshing blind.
187187 mkdirSync ( dir , { recursive : true , mode : 0o700 } ) ;
188188 // mkdirSync only applies the mode at creation; re-apply owner-only on an
189- // existing directory so a permissive pre-existing dir is corrected.
190- try { chmodSync ( dir , 0o700 ) ; } catch { /* best-effort */ }
189+ // existing directory so a permissive pre-existing dir is corrected. Fail
190+ // closed: if the directory cannot be hardened to owner-only, do not write
191+ // refresh-intent data into a directory a local attacker may observe.
192+ chmodSync ( dir , 0o700 ) ;
191193 hardenConfigDir ( ) ;
192194 const path = refreshIntentPath ( refreshToken ) ;
193195 try {
@@ -558,13 +560,15 @@ async function pollForToken(
558560 // current wait interval. The device-code grant is idempotent for the
559561 // pending case, so a retried poll is safe (unlike the refresh path).
560562 if ( signal ?. aborted ) throw new Error ( "Login cancelled" ) ;
561- await sleep ( waitMs , signal ) ;
563+ const remainingMs = deadline - Date . now ( ) ;
564+ if ( remainingMs <= 0 ) break ;
565+ await sleep ( Math . min ( waitMs , remainingMs ) , signal ) ;
562566 continue ;
563567 }
564568 // Parse once and pass the payload through to the failure path (review #8),
565569 // so we never try to re-read a body that has already been consumed.
566570 const payload = ( await response . json ( ) . catch ( ( ) => ( { } ) ) ) as NousTokenResponse ;
567- if ( response . ok && nonEmptyString ( payload . access_token ) ) return parseTokenPayload ( payload , "" ) ;
571+ if ( response . ok ) return parseTokenPayload ( payload , "" ) ;
568572 const error = payload . error ;
569573 if ( error === "authorization_pending" ) {
570574 await sleep ( waitMs , signal ) ;
0 commit comments