This repository has been archived by the owner on Jan 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix #4882, use different secrets for different signing purposes 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. Additionally, do not allow the download filename created for one image to be used for 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.
- Loading branch information
Showing
8 changed files
with
137 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ALTER TABLE signing_keys ADD COLUMN scope TEXT; | ||
-- We don't want 'legacy' to actually be the default, we just want to set our existing | ||
-- keys to this scope, and force new keys to have an explicit scope set: | ||
UPDATE signing_keys SET scope = 'legacy'; | ||
ALTER TABLE signing_keys ALTER COLUMN scope SET NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE signing_keys DROP COLUMN scope; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from __future__ import print_function | ||
from clientlib import ScreenshotsClient | ||
import urllib | ||
|
||
|
||
def test_download_key(): | ||
user = ScreenshotsClient() | ||
user.login() | ||
shot_1_url = user.create_shot(docTitle="A_TEST_SITE_1") | ||
shot_2_url = user.create_shot(docTitle="A_TEST_SITE_2") | ||
shot_1_page = user.read_shot(shot_1_url) | ||
shot_2_page = user.read_shot(shot_2_url) | ||
shot_1_download_url = shot_1_page["download_url"] | ||
shot_2_download_url = shot_2_page["download_url"] | ||
resp = user.session.get(shot_1_download_url) | ||
# This should normally work: | ||
print("Normal download URL:", shot_1_download_url) | ||
assert resp.headers["Content-Disposition"], "Should get a proper download response" | ||
mixed_up = shot_1_download_url.split("?")[0] + "?" + shot_2_download_url.split("?")[1] | ||
# Getting mixed_up should fail, since the signed download parameter comes from shot_2 | ||
# but we're fetching the image from shot_1 | ||
resp = user.session.get(mixed_up) | ||
print("Mixed-up URL:", mixed_up) | ||
print("Response:", resp) | ||
print("Content-Disposition header:", resp.headers.get("Content-Disposition")) | ||
assert not resp.headers.get("Content-Disposition"), "The signature shouldn't work" | ||
|
||
|
||
def test_scopes(): | ||
user = ScreenshotsClient() | ||
user.login() | ||
abtests = user.session.cookies["abtests"] | ||
abtests_sig = user.session.cookies["abtests.sig"] | ||
print(abtests, abtests_sig) | ||
shot = user.create_shot(docTitle="A_TEST_SITE") | ||
page = user.read_shot(shot) | ||
download_url = page["download_url"] | ||
resp = user.session.get(download_url) | ||
assert resp.headers.get("Content-Disposition") | ||
mixed_up = "%s?download=%s&sig=%s" % ( | ||
download_url.split("?")[0], | ||
urllib.quote(abtests), | ||
urllib.quote(abtests_sig), | ||
) | ||
resp = user.session.get(mixed_up) | ||
assert not resp.headers.get("Content-Disposition") | ||
|
||
|
||
if __name__ == "__main__": | ||
test_download_key() | ||
test_scopes() |