Skip to content
Tutorials Center
My learning

Topics

Lesson 42 of 55 ยท Compliance, Security, Review

App Security Checklist

A practical security checklist for Shopify apps: secrets, least-privilege scopes, XSS and CSRF in embedded apps, CSP frame-ancestors and validating every inbound request.

A Shopify app is a small web service that holds keys to many stores. If an attacker gets into your app, they get an access token for every merchant who installed it. Security is therefore not a feature you add at the end; it is part of why merchants and the App Store can trust you. The good news is that most of the platform's risks fall into a handful of habits, and the app template already does many of them for you.

This lesson is a checklist you can use while building and again before you submit. For each item you will see the reason, the typical mistake and, where it helps, a runnable stand-in. The platform configuration and route code are read-only; the stand-ins are plain JavaScript that show the logic. General web-shop security ideas are in Shop Security; here we focus on what is specific to Shopify apps.

1. Treat secrets as secrets

Your app has several values that must never reach a browser, a repository or a log:

Secret What it protects
Client secret (API secret key) Signs and verifies webhooks, the install redirect and session tokens
Access tokens (offline and online) Calls to each shop's Admin API
Database credentials, queue and email keys Everything your own infrastructure holds

Rules that prevent most leaks:

  • Keep them in environment variables or a secret manager, loaded on the server. Commit a .env.example with fake values, and add .env to .gitignore before the first commit.
  • Never put a secret in code that is bundled for the browser. In a Vite or React Router app, anything imported by client code ends up public. Check what your build exposes.
  • Encrypt access tokens at rest if you store them yourself, and keep database backups as protected as the database.
  • Scrub logs: log the shop domain and request id, not tokens, signatures or full webhook bodies.
  • Know how to rotate: if the client secret leaks, you change it in the app settings and redeploy. Practice this before you need it, and read Token Exchange and Access Tokens for how tokens are issued and stored.

2. Ask for the least access

Every scope you request is power an attacker would inherit. A review-widget app that asks for write_orders raises questions from merchants and from Shopify's reviewers. Request only what features need, prefer read scopes, and use optional scopes for rarely used features (Managed Installation and Access Scopes). Fetch customer data only if you truly need it, and remember that protected customer data needs its own approval.

3. Validate every inbound request

Your app receives several kinds of requests, and each has its own proof of origin. A route that skips the proof is a hole.

flowchart LR
    A["Install redirect"] -->|"HMAC and state"| OK["Your app"]
    B["Embedded page request"] -->|"session token JWT"| OK
    C["Webhook"] -->|"HMAC of raw body"| OK
    D["App proxy request"] -->|"signature parameter"| OK
    E["Anything else"] -->|"no proof"| X["Reject"]

Match each route to the proof it must check.

Also validate values inside a valid request. The shop parameter is a good example: if your code builds a URL from it, an attacker could pass a domain they control. Accept only real Shopify shop domains.

JS Validate the shop parameter before using it

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Only the first two lines pass (the second after lower-casing). The anchors ^ and $ are what reject domains that merely contain the right text. A regular expression without anchors is a classic bug here.

4. XSS in an embedded app

Cross-site scripting means an attacker gets their text to run as script in your page. Your embedded app runs inside the merchant's admin session, so injected script could call your backend with the merchant's session token. Typical sources of attacker text are product titles, customer notes and order fields: merchants and customers control those, not you.

  • Use a framework that escapes by default (React does). Be suspicious of dangerouslySetInnerHTML, innerHTML and server-rendered HTML built by string concatenation.
  • Never put untrusted text into a URL, an attribute or a <script> block without the matching encoding.
  • If you must render rich text, run it through a maintained sanitizer with an allow-list.
  • Do not load scripts you do not control, and pin versions of those you do.
JS Escaping untrusted text

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The unsafe version contains a live <img> element whose error handler would run script. The safe version turns the angle brackets into text, so the browser shows the characters instead of running them. In React this happens automatically when you write in JSX; the danger returns only when you opt out of it.

5. CSRF and the iframe

Cross-site request forgery tricks a browser into sending a request that carries the user's cookies. Embedded apps avoid the main risk by not using cookies for authentication: the browser cannot attach a session token automatically, because the app adds it to the Authorization header with JavaScript. A foreign site cannot do that. Keep it that way:

  • Authenticate state-changing requests (POST, PUT, DELETE) with the session token, never with a cookie alone.
  • If you do use cookies anywhere (for example for a non-embedded page), set Secure, HttpOnly and a suitable SameSite value, and add a CSRF token.
  • Do not accept state changes through GET requests.

6. Content Security Policy and frame-ancestors

Your app is displayed in an iframe inside the Shopify admin. If any website could frame it, an attacker could overlay it with invisible elements and trick merchants into clicking (clickjacking). The cure is the frame-ancestors directive of the Content-Security-Policy header: it lists who may frame your pages. For an embedded app that is the specific shop's admin and Shopify's admin host, nothing else.

The app template sets this header in its response handler. That code is read-only here; the stand-in below shows how the header value is built, so you understand what you would be checking.

JS Build a frame-ancestors header

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice what the builder does when it gets a bad shop value: it falls back to the narrow default instead of echoing the input into the header. Echoing user input into a header is also a header injection risk, which is another reason to validate the shop first. Do not use the older X-Frame-Options header for embedded pages: it cannot express "this one shop" and may block the legitimate iframe.

Shopify's documentation lists the exact frame-ancestors values it expects for embedded apps, including values for its internal environments. Copy those from the current documentation or the template; the stand-in above only shows the idea.

7. Dependencies and the build

Your app is mostly other people's code. Supply-chain problems are real and boring to fix.

  • Commit the lockfile and install with it in CI (npm ci) so builds are repeatable.
  • Run your package manager's audit regularly and update the Shopify packages: the platform deprecates old API versions and old library versions on a schedule (API Versioning and Deprecations).
  • Remove unused packages; each one is attack surface.
  • Keep build and deploy credentials separate from runtime secrets, and give CI the minimum permissions.
  • Use HTTPS everywhere, including between your app and its database when the network is shared.

8. Before you submit

Run through this list. The App Store review (App Store Requirements and Review) checks many of these.

  • No secret in the repository, the client bundle or the logs
  • Scopes are the minimum, and protected data is used only with approval
  • Every route verifies its own proof (session token, HMAC, proxy signature)
  • The shop parameter and other inputs are validated with anchored patterns
  • Untrusted text is escaped; no unsafe HTML sinks
  • frame-ancestors is set and not a wildcard
  • The mandatory privacy webhooks work (Privacy, GDPR and Mandatory Webhooks)
  • Dependencies are current and the lockfile is committed
  • You can rotate the client secret and revoke tokens

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which header controls which sites may display your embedded app in an iframe?

    frame-ancestors in the Content-Security-Policy header lists the origins allowed to frame the page. It is the modern defense against clickjacking.
  2. 2. Why is the session-token design a good defense against CSRF in an embedded app?

    CSRF abuses credentials the browser attaches by itself, such as cookies. A bearer token that your code must add explicitly is not attached to a forged request.
  3. 3. Why must a shop-domain regular expression be anchored with ^ and $?

    An unanchored pattern only checks that the text appears somewhere in the string, so hostile domains that contain it pass. Anchors force the whole string to match.
  4. 4. A product title contains <img onerror=...>. Which approach is safe?

    Rendering as text lets the browser display the characters without interpreting them. Blocklists of words are easy to bypass, and innerHTML or concatenation executes the markup.
  5. 5. Where should the client secret live?

    The client secret signs and verifies requests, so exposing it lets anyone forge them. Keep it on the server and out of the repository.

Summary

  • Keep secrets on the server, out of the repository, bundle and logs; encrypt stored tokens and practice rotation.
  • Request the fewest scopes, and handle protected customer data only with approval and a clear need.
  • Every inbound route needs its own proof: session token, webhook HMAC, proxy signature or OAuth checks; also validate values such as the shop parameter with anchored patterns.
  • Escape untrusted text, avoid unsafe HTML sinks, and rely on bearer session tokens instead of cookies for state changes.
  • Send a narrow frame-ancestors policy, keep dependencies current and run the pre-submission checklist.

Next: App Store Requirements and Review