Skip to content

Conversation

isoos
Copy link
Collaborator

@isoos isoos commented Oct 29, 2024

No description provided.

@isoos isoos requested review from jonasfj and sigurdm October 29, 2024 12:37
Comment on lines 1177 to 1192
final versionState = state.versions![version];
if (versionState == null) {
// check if the task was aborted
final abortedToken =
state.abortedTokens?.firstWhereOrNull((t) => t.token == token);
if (abortedToken != null && abortedToken.expires.isBefore(clock.now())) {
throw TaskAbortedException('$package/$version has been aborted.');
}
// otherwise throw a generic not found error
throw NotFoundException.resource('$package/$version');
}

// Check the secret token
if (!versionState.isAuthorized(token)) {
throw AuthenticationException.authenticationRequired();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is vulnerable to timing attacks!

I'd suggest adding an isAuthorized method to AbortedTokenInfo object.

Also versionState != null doesn't imply that the token couldn't be aborted.

I'd suggest:

  • Always check abortedTokens, ideally always compare all of them (not just the first, because we want fixed time behavior)
  • Then check versionState.isAuthorized

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

isoos and others added 7 commits November 4, 2024 09:03
Co-authored-by: Jonas Finnemann Jensen <jopsen@gmail.com>
Co-authored-by: Jonas Finnemann Jensen <jopsen@gmail.com>
Co-authored-by: Jonas Finnemann Jensen <jopsen@gmail.com>
Co-authored-by: Jonas Finnemann Jensen <jopsen@gmail.com>
@isoos isoos requested a review from jonasfj November 4, 2024 08:51
.map(
(vs) => AbortedTokenInfo(
token: vs.secretToken!,
expires: vs.scheduled.add(maxTaskExecutionTime),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have stored scheduled instead of expires, not that it matters more, but it would have been 10% more canonical.

Anyways, I don't think it matters :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could replace it, but I'm not sure it is worth it...

@isoos isoos merged commit eacba32 into dart-lang:master Nov 6, 2024
32 checks passed
@isoos isoos deleted the worker-upload branch November 6, 2024 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants