Improve embedded requests detection with Sec-Fetch-Dest
header
#1873
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.
What this PR does
Token exchange concern uses
embedded
param to determine whether request should be redirected to embedded or bounce page should be displayed: https://github.com/Shopify/shopify_app/blob/main/lib/shopify_app/controller_concerns/token_exchange.rb#L67It works well when the app just loaded and Shopify provided all necessary params with id_token. But subsequent requests in app won't have
![image](https://private-user-images.githubusercontent.com/839922/345803472-240fcd33-d6be-4fe0-bbd7-a3e9d4bff28b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNDcyNDIsIm5iZiI6MTczOTA0Njk0MiwicGF0aCI6Ii84Mzk5MjIvMzQ1ODAzNDcyLTI0MGZjZDMzLWQ2YmUtNGZlMC1iYmQ3LWEzZTlkNGJmZjI4Yi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwOFQyMDM1NDJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0xODJiZGQzMzA5ZDIyMTJmZjI3Mzc2YmY3NjYyNDI2ZTlhMzMyMzBkMzljYTkzYzVlZTViMTA1MmIzYjg3M2Y2JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.m8AcZL5I_GDEyOagtg5StxubWDEMemlnMp1fAB_RH0U)
embedded
param in the URL. Meaning, that in case of invalid token error, the app will try to redirect user to embedded within iframe and it will lead to browser error:To solve this problem, I found an alternative way to detect embedded using
Sec-Fetch-Dest
browser header. It's a nice fallback toembedded
param and should help us correctly detect embedded requests and redirect them properly.References:
Checklist
Before submitting the PR, please consider if any of the following are needed:
CHANGELOG.md
if the changes would impact usersREADME.md
, if appropriate./docs
, if necessary