Skip to main content

Shop domain validation regex is not anchored

Detects unanchored myshopify.com regexes that allow domain spoofing and token theft.

DetailValue
Check IDWEAK_SHOP_VALIDATION
SeverityHigh
How it runsAgent review

app/utils/shop.server.ts

// Unanchored: "evil.com/x.myshopify.com" and
// "shop.myshopify.com.evil.test" both match, so a forged shop
// value passes validation and reaches token lookup.
const SHOP_PATTERN = /[a-zA-Z0-9-]+\.myshopify\.com/;

export function isValidShop(shop: string) {
return SHOP_PATTERN.test(shop);
}

Anchor the regex with ^ and $ to prevent prefix/suffix attacks.

For more detail, see Authorization code grant.

app/utils/shop.server.ts

// Anchored at both ends, so the whole string has to be the shop
// domain.
const SHOP_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9-]*\.myshopify\.com$/;

export function isValidShop(shop: string) {
return SHOP_PATTERN.test(shop);
}


Was this page helpful?