Regarding exposure of “PUBLIC_STOREFRONT_API_TOKEN” #2687
Replies: 1 comment
-
Perhaps it is obvious, but I have confirmed that if “PUBLIC_STOREFRONT_API_TOKEN” is exposed, anyone can easily manipulate the cart using curl or other means. The target cart ID can be easily retrieved from the cookie of the traditional online store and the store made by Hydrogen template. Below is a forum about similar restrictions on the traditional online store.(in Japan) This forum seems to have come to the conclusion that it is possible to limit product combinations by “not rendering the checkout link on the cart page”. However, if the “PUBLIC_STOREFRONT_API_TOKEN” is exposed, it can be easily manipulated. And the Hydrogen template exposes it to the browser via |
Beta Was this translation helpful? Give feedback.
-
Question
Are there any required components or libraries in this project that use or expose “PUBLIC_STOREFRONT_API_TOKEN”(public access)?
Or is there a possibility that such code will be included in the future?
Why
I understand that most of the requests to storefront-api in this project will be made via server-side “PRIVATE_STOREFRONT_API_TOKEN”(private access).
I am asking this question because if it is promised that only “private access” will be used in the future, then it may be possible to bypass some of Shopify's limitations without having to install an app or upgrade a plan.
e.g. Uber eats toppings
We can add “more vegetables” or “garlic” to “ramen”, and the price is added accordingly.
uber-eats-toppings.mov
But to accomplish this in shopify, we are limited to the following options, even though we are a headless developer.
I don't expect it to get much better in the future, as these features are very much tied to the traditional “online store”.
So I want to focus on what we can do within the limitations of the platform.
e.g.) Avoiding limitations on the number of product options, variations https://www.youtube.com/watch?v=vOaeMvD1CK0
Solution
Going back to the “Uber eats toppings”, let's say we want to implement “additional products” through metafields and metaobjects.
The simplest way to do this would be to add a “product list type metafield” to the product.
If the store owner adds the options “more vegetables” and “garlic” to the meta field for ramen, the developer can simply include a UI that allows these toppings to be added.
If the store owner does not want to sell the toppings alone, the product page can simply return a 404.
Problem
But the problem is the cart.
If there is no code in the Hydrogen project to expose the “public access token” in a required component, library, etc., we can disallow the toppings-only request in the request to the cart.
We can also disallow the use of “public access” and ask the store owner to protect the token.
I believe that if we can “maximize the benefits of server-side development”, we will have a much wider range of development options.
Or is it more like “don't implement this, just add more apps or upgrade your plan”?
Beta Was this translation helpful? Give feedback.
All reactions