File tree Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -1190,18 +1190,18 @@ PackageVersionStateInfo _authorizeWorkerCallback(
11901190 PackageState state,
11911191 String token,
11921192) {
1193+ // fixed-time verification of aborted tokens
1194+ final isKnownAbortedToken = state.abortedTokens
1195+ ? .map ((t) => t.isAuthorized (token))
1196+ .fold <bool >(false , (a, b) => a || b);
1197+ if (isKnownAbortedToken ?? false ) {
1198+ throw TaskAbortedException ('$package /$version has been aborted.' );
1199+ }
1200+
11931201 final versionState = state.versions! [version];
11941202 if (versionState == null ) {
1195- // check if the task was aborted
1196- final abortedToken =
1197- state.abortedTokens? .firstWhereOrNull ((t) => t.token == token);
1198- if (abortedToken != null && abortedToken.expires.isBefore (clock.now ())) {
1199- throw TaskAbortedException ('$package /$version has been aborted.' );
1200- }
1201- // otherwise throw a generic not found error
12021203 throw NotFoundException .resource ('$package /$version ' );
12031204 }
1204-
12051205 // Check the secret token
12061206 if (! versionState.isAuthorized (token)) {
12071207 throw AuthenticationException .authenticationRequired ();
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import 'dart:convert' show json;
77import 'package:clock/clock.dart' ;
88import 'package:json_annotation/json_annotation.dart' ;
99import 'package:pub_dev/admin/actions/actions.dart' ;
10+ import 'package:pub_dev/shared/utils.dart' ;
1011
1112import '../shared/datastore.dart' as db;
1213import '../shared/versions.dart' as shared_versions;
@@ -433,6 +434,10 @@ class AbortedTokenInfo {
433434 Map <String , dynamic > toJson () => _$AbortedTokenInfoToJson (this );
434435
435436 bool get isNotExpired => clock.now ().isBefore (expires);
437+
438+ bool isAuthorized (String token) {
439+ return fixedTimeEquals (this .token, token) && isNotExpired;
440+ }
436441}
437442
438443/// A [db.Property] encoding a List os [AbortedTokenInfo] as JSON.
You can’t perform that action at this time.
0 commit comments