This repository was archived by the owner on Jul 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
Fix part of #60 #61
Open
hpawe01
wants to merge
2
commits into
Shopify:master
Choose a base branch
from
hpawe01:patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+13
−4
Open
Fix part of #60 #61
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,18 +1,27 @@ | ||
| module.exports = function withShop({ authBaseUrl } = {}) { | ||
| return function verifyRequest(request, response, next) { | ||
| const { query: { shop }, session, baseUrl } = request; | ||
| const { query = {}, session = {}, baseUrl } = request; | ||
| const { accessToken } = session; | ||
| const shop = getShopFromReferrer(request.get('referer')) || query.shop; | ||
|
|
||
| if (session && session.accessToken) { | ||
| if (accessToken && session.shop === shop) { | ||
| next(); | ||
| return; | ||
| } | ||
|
|
||
| if (shop) { | ||
| response.redirect(`${authBaseUrl || baseUrl}/auth?shop=${shop}`); | ||
| response.redirect(`${authBaseUrl || baseUrl}/auth/shopify?shop=${shop}`); | ||
| return; | ||
| } | ||
|
|
||
| response.redirect('/install'); | ||
| return; | ||
| }; | ||
|
|
||
| function getShopFromReferrer(referrer) { | ||
| if (!referrer) { | ||
| return; | ||
| } | ||
| const result = referrer.match(/shop=([^&]+)/); | ||
| return result && result[1]; | ||
| } | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is concerning to me from a security perspective – could this allow an arbitrary user to log in as a given shop if they spoof the referrer?
The code as is wouldn't even require explicit spoofing – any referring URL with the
shopparameter would be able to log in as the provided shop given that this shop has previously authed and we have an access token stored.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They need to have an access token in express's session, which means they've logged in before. We could also pull up the shop in question and check if the accessToken matches, which I opened an issue for. #64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jamiemtdwyer Actually the referrer is just another way to get the
shopname. If an arbitrary user could log in as a given shop by spoofing the referrer, they could do it already at the moment by providing the GET parametershop.So this pull request is independent of the security issue you describe. As @TheMallen points out in #64 it is not the question how we determine, which shop is requested, but if the current session token matches the requested shop.