Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Fix #4882, use different secrets for different signing purposes #4883

Merged
merged 7 commits into from
Sep 17, 2018

Conversation

ianb
Copy link
Contributor

@ianb ianb commented Sep 12, 2018

This adds signing 'scopes', so that if you get something signed for one scope, you can't use it for another scope. E.g., you can't get a download URL and use that for an authentication key.

This keeps the 'legacy' scope, which is the current single key. This can be used now to make sure everything works when people upgrade, but removed later as people have used to the new specific scopes. But nothing new will be signed with the legacy scope once this is deployed.

This also updates some functions to use async/await.

This adds signing 'scopes', so that if you get something signed for one scope, you can't use it for another scope. E.g., you can't get a download URL and use that for an authentication key.

This keeps the 'legacy' scope, which is the current single key. This can be used now to make sure everything works when people upgrade, but removed later as people have used to the new specific scopes. But nothing new will be signed with the legacy scope once this is deployed.

This also updates some functions to use async/await.
@ianb ianb requested a review from g-k September 12, 2018 19:50
Copy link
Contributor

@g-k g-k left a comment

Choose a reason for hiding this comment

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

Looks good! We should add tests for:

  • a request with one scope cannot be used for a different scope/action
  • a request with the same scope has a unique resource ID (proxy url, download filename, etc.) and cannot be used to fetch a different resource with the same scope
  • a request with a legacy scope cannot be used to request new-scope resources

A test for the scope upgrade process would be good too.

textKeysByScope = fetchedTextKeysByScope;
keysByScope = {};
for (const scope in textKeysByScope) {
keysByScope[scope] = new Keygrip(textKeysByScope[scope]);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also bump the HMAC algorithm:

new Keygrip(textKeysByScope[scope], 'sha256');

@ianb
Copy link
Contributor Author

ianb commented Sep 12, 2018

a request with the same scope has a unique resource ID (proxy url, download filename, etc.) and cannot be used to fetch a different resource with the same scope

Ah, good point, I'm pretty sure that's not currently correct

a request with a legacy scope cannot be used to request new-scope resources

The intention is for that to be allowed, with #4884 to remove those keys, since that's the migration strategy we have here.

We should also bump the HMAC algorithm

That's also going to break migration, unless we actually instantiate two Keygrips and do our own fallback checking, and/or wrap Keygrip.

I don't think breaking signatures for downloading matters, but we can't break the authentication headers.

@g-k
Copy link
Contributor

g-k commented Sep 12, 2018

The intention is for that to be allowed, with #4884 to remove those keys, since that's the migration strategy we have here.

Ah OK, I misunderstood the migration plan.

That's also going to break migration, unless we actually instantiate two Keygrips and do our own fallback checking, and/or wrap Keygrip.

OK that can be a separate issue for later.

…or another image

Before this change you could take the ?download=...&sig=... from one image and put it on another image URL, causing that other image to be downloaded with the other filename.
@ianb
Copy link
Contributor Author

ianb commented Sep 14, 2018

This should be ready, except for the errors in CircleCI. The server tests pass for me locally. I haven't been able to see what the error is; it's a 500 error in the server, but I'm not seeing the server logs in Artifacts.

@@ -13,7 +13,8 @@ exports.createProxyUrl = function(req, url, hash) {
};

exports.createDownloadUrl = function(url, filename) {
const sig = dbschema.getKeygrip().sign(new Buffer(filename, "utf8"));
const path = (new URL(url)).pathname;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs const { URL } = require("url");

In newer Node versions URL is a built-in, but not all versions we're using
@chenba
Copy link
Collaborator

chenba commented Sep 17, 2018

Just a couple flake8 lint errors now.

@ianb
Copy link
Contributor Author

ianb commented Sep 17, 2018

Green at last! Will squash and merge...

@ianb ianb merged commit 429a593 into master Sep 17, 2018
@ianb ianb deleted the scoped-keygrip branch September 17, 2018 19:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants