Shopify Access Token Regex for PHP
/^shpat_[a-fA-F0-9]{32}$|^shpca_[a-fA-F0-9]{32}$|^shppa_[a-fA-F0-9]{32}$|^shpss_[a-fA-F0-9]{32}$/What this pattern does
This page provides a comprehensive, battle-tested regular expression for matching shopify access token, ported and verified for PHP. In security-sensitive code, using an unverified regex can open the door to both false positives and denial-of-service attacks. The snippet below is ready to drop into your PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.
Php Implementation
<?php
// Shopify Access Token
// ReDoS-safe | RegexVault — Security > API Keys & Tokens
define('SHOPIFY_ACCESS_TOKEN_PATTERN', '/^shpat_[a-fA-F0-9]{32}$|^shpca_[a-fA-F0-9]{32}$|^shppa_[a-fA-F0-9]{32}$|^shpss_[a-fA-F0-9]{32}$/');
function validate_shopify_access_token(string $input): bool {
return (bool) preg_match(SHOPIFY_ACCESS_TOKEN_PATTERN, $input);
}
// Example
var_dump(validate_shopify_access_token("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")); // bool(true)Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
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 | shpat_short |
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 | SHPAT_a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4 |
| — | shpat_a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d |
When to use this pattern
This pattern is drawn from the Security > API Keys & Tokens category and carries a ReDoS-safe certification. That matters for PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.
Common Pitfalls
Shopify tokens are store-scoped. A leaked token only affects the specific store it was issued for. Rotate immediately and review audit logs in Shopify Partners dashboard.
Technical Notes
Shopify token prefixes: shpat_=access token, shpca_=custom app token, shppa_=partner app token, shpss_=shared secret. All are 32 hex chars after the prefix. Each is scoped to a specific store.
Have a pattern that belongs in the vault?
Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.
Submit a Pattern