@nitrogen/auth #32
Replies: 4 comments 2 replies
-
|
@clough-sram I've used this in production for a few storefronts this year and for one personal store, and before that always worked headless with Shopify and Vue. The short answer, is no. I have never seen a case where the Storefront access token causes any risks when being available on client-side. This is mainly do to the fact you can't really do anything with the access token besides fetch content that is already on the store. In fact, most headless storefronts expose this token and it can be found within the file sources in dev tools if a developer really knows where to look. With the Admin API access token, you are technically able to edit products, collections, and customer account data. The Admin access token is also set client-side in this template, but honestly I also have never seen a case where exposing this causes any risks either because you are able to limit scopes within the Admin API setup. The only use-case I've ever used the Admin access token for is for creating wishlist functionality or unique customer accounts that allow customers to cancel subscriptions, so pretty much only customer-scoped features. Above all else, its important to know that both the Storefront and Admin API access tokens are encrypted. For this template, I host with Cloudflare Workers via Nuxt Hub, which allows the option to encrypt environment variables such as the access tokens (I just encrypt all my API-based environment variables normally). I scanned through the raw output files in the browser a few months ago and indeed the token values cannot be found anywhere. I think this feature is also available within Vercel. I always go with Cloudflare when it comes to ecom due to the potential price difference, which can be substantial if you are working with a popular store. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @rylanharper , appreciate the quick response. Just wanted to clarify that I was referring to the
My understanding is that if this were captured from the client, you could technically log in as the customer. This could expose order history, addresses. Does Pinia have any measures to prevent this? Do you think it matters? |
Beta Was this translation helpful? Give feedback.
-
|
Ohh got it! You're right to point this out. To be honest, I haven't done much to address this just because the chance of an XSS attack when using a headless storefront via Shopify is extremely low. But yes, it could possibly happen if a nefarious actor gets the token and sends a GraphQL request via a CURL command or something. I can think of two options to address this issue:
Thats pretty much my two-cents on it.. I honestly think the chances of an attack with this token are extremely rare, like to the point where it most likely will never happen. However, it is possible. I guess this is an oversight on my end in this project. I'm open to any suggestions you have, or a PR that can make this project a bit more secure. |
Beta Was this translation helpful? Give feedback.
-
|
Hey @clough-sram, I am working on some updates for this project this week.. What you you think of this approach specifically? persist: {
pick: ['accessToken', 'customer'],
storage: piniaPluginPersistedstate.cookies({
sameSite: 'strict',
secure: !import.meta.dev,
maxAge: 60 * 60 * 24, // 24 hours
}),
},I have yet to test this out fully, but it seems like a much more viable option. This projects against the following: ✅ CSRF attacks (can't trick user into making requests) However, it does not fully prevent a possible XSS attack, which again, would be exceptionally rare and likely may never happen in the average storefront's lifecycle. If you need this, I would recommend using Shopify's built-in account system. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Hey @rylanharper, thanks for making this available. We have been playing around with the starter and hoping to make the jump to a production environment on Vercel with a Shopify Plus store. Do you think there are any concerns with the
accessTokenbeing on the client side?Does Pinia have any measures to mitigate the risk of that token being accessible in the browser? Does this even matter for a Shopify store?
Appreciate any insight or direction you may have.
Beta Was this translation helpful? Give feedback.
All reactions