Dev.to Security 🔐 Cybersecurity 👁 2 📖 3 min read

Shopify Dec 8 allowed_sources & Jan 1, 2027 Expiring Offline Tokens: Stopping Concurrent Webhook 401 Storms

If you maintain a public or custom Shopify app, three enforcement dates are colliding right now: December 8, 2026 (3 days away): shopify app deploy rejects apps whose shopify.app.toml is missing valid network_access.a

If you maintain a public or custom Shopify app, three enforcement dates are colliding right now:

  • December 8, 2026 (3 days away): shopify app deploy rejects apps whose shopify.app.toml is missing valid network_access.allowed_sources declarations (or breaks the 20-origin cap, uses * wildcards, uses http://, or forgets S3/GCS bucket origins).
  • January 1, 2027 (27 days away): Shopify's Public App Store delists apps still relying on legacy non-expiring offline access tokens (expiringOfflineAccessTokens disabled), with hard HTTP 403 enforcement following April 1.
  • IP Allowlist & Static Egress: Apps running on dynamic serverless egress IPs (Vercel/Netlify/Lambda default NAT) need explicit static egress strategy or allowlist updates where required.

Failure Mode #1 (Dec 8): network_access.allowed_sources Rejections

Common causes of immediate deploy failure on Dec 8:

  • Leaving http:// URLs or wildcard subdomains (https://*.amazonaws.com) in allowed_sources.
  • Exceeding Shopify's 20-origin cap.
  • Forgetting outbound origins called inside UI extensions or app proxies (e.g., direct S3/GCS asset uploads, Sentry/PostHog, Stripe, or custom microservice domains).

Verify your shopify.app.toml cleanly declares exact HTTPS origins (preserving required bucket path prefixes for S3/GCS):

[access.admin]
direct_api_mode = "offline"

[network_access]
allowed_sources = [
  "https://api.yourapp.com",
  "https://storage.googleapis.com/your-public-bucket"
]

Failure Mode #2 (Jan 1): Concurrent Webhook 401 Storms

Flipping expiringOfflineAccessTokens = true and adding refreshToken / refreshTokenExpires columns to your Prisma Session table is only half the fix.

Once offline access tokens expire every 60 minutes, watch what happens in production when a busy merchant receives a burst of 10 simultaneous webhooks (orders/create, orders/updated, inventory_levels/update) right after minute 60:

  1. Workers 1–10 all read the same expired session row from Postgres.
  2. All 10 call Shopify's OAuth refresh endpoint concurrently using the same single-use refreshToken.
  3. Worker 1 succeeds and rotates the refresh token.
  4. Workers 2–10 get HTTP 400/401 invalid refresh token, retry, fail merchant webhook processing, and trigger a 401 storm (already biting production apps in Shopify/shopify-app-js#3540).

The Fix: Distributed Single-Flight Refresh Mutex (Redis or Postgres)

Wrap your token refresh in a per-shop distributed lock AND re-read the session row inside the lock before calling Shopify (classic double-checked locking):

// PostgreSQL advisory-lock single-flight refresh (zero extra infra if you already run Postgres)
export async function getFreshShopToken(
  shop: string,
  db: {
    withAdvisoryLock<T>(lockKey: string, fn: () => Promise<T>): Promise<T>;
    getSession(shop: string): Promise<{ accessToken: string; refreshToken: string; expiresAt: number }>;
    saveSession(shop: string, next: { accessToken: string; refreshToken: string; expiresAt: number }): Promise<void>;
  },
  exchangeRefreshToken: (shop: string, refreshToken: string) => Promise<{ accessToken: string; refreshToken: string; expiresAt: number }>
): Promise<string> {
  const SKEW_MS = 60_000;
  const cached = await db.getSession(shop);
  if (cached.expiresAt - Date.now() > SKEW_MS) return cached.accessToken;

  return db.withAdvisoryLock(`shopify:refresh:${shop}`, async () => {
    // Re-check inside the lock: if a sibling webhook just refreshed, reuse it!
    const current = await db.getSession(shop);
    if (current.expiresAt - Date.now() > SKEW_MS) return current.accessToken;

    const fresh = await exchangeRefreshToken(shop, current.refreshToken);
    await db.saveSession(shop, fresh);
    return fresh.accessToken;
  });
}

Under a 10-concurrent-webhook burst, exactly 1 OAuth refresh call fires and the other 9 workers cleanly reuse the freshly persisted token with 0% 401 errors.

Free Local Audit CLI & Browser Checker (Zero Upload)

We open-sourced a zero-dependency Node 22 CLI (MIT) that scans shopify.app.toml, package.json, prisma/schema.prisma, and outbound fetch calls locally to flag Dec-8 and Jan-1 blockers before deploy:

# Run against the bundled failing demo Shopify app
npx -y github:spleyapp/shopcliff-check --demo

# Audit your actual Shopify app repo locally
npx -y github:spleyapp/shopcliff-check /path/to/your-shopify-app --markdown

Prefer checking in the browser? Drop your shopify.app.toml, package.json, and schema.prisma into our 100% client-side auditor + interactive Naive vs Locked 401 Storm Simulator at shopcliff.netlify.app (files never leave your browser).

Links & Full Disclosure

(Disclosure: the CLI and browser checker are completely free/MIT. We offer an optional $49/$99 Compliance Survival Kit ZIP on the site containing the full batch migrateToExpiringToken() runner with 429 backoff/checkpointing, tested Redis Lua + Postgres advisory-lock mutexes, and Prisma/Drizzle/SQL migrations.)

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.