OptStuff

Domain Whitelisting

Configure project-level image source domains and authorized websites to control which images can be processed and who can use your service.

OptStuff provides two layers of domain whitelisting at the project level, each serving a different purpose.

Two-Layer Architecture

LayerQuestionValidationConfigured In
Authorized Websites (allowedRefererDomains)WHO can use this service?HTTP Referer headerProject Settings
Image Sources (allowedSourceDomains)WHAT image sources can be processed?Image URL in requestProject Settings

Both layers are configured in the project's Settings tab under Domain Security.

Configuring Image Sources (Project Level)

  1. Navigate to Dashboard → Project → Settings
  2. In Image Sources, add the domains where your images are hosted
  3. Use protocol-prefixed entries (for example https://images.example.com)
  4. Subdomain matching: adding https://example.com allows example.com and all subdomains (cdn.example.com, img.example.com, ...)
List StatusProduction BehaviorDevelopment Behavior
Empty (default)Reject all requests (fail closed)Allow all sources (for convenience)
Non-emptyOnly listed domains allowedOnly listed domains allowed

Important: Always configure at least one image source domain before using OptStuff in production. In production, an empty source list rejects all requests.

Configuring Authorized Websites (Project Level)

  1. Navigate to Dashboard → Project → Settings
  2. In Authorized Websites, add your website domains
  3. Use protocol-prefixed entries (for example https://app.example.com)
  4. Subdomains are not implied for exact host entries; use wildcard when needed:
    • https://app.example.com → only this host
    • https://*.example.com → all subdomains (and example.com)
List StatusBehavior
Empty (default)All referers allowed
Non-emptyOnly listed domains allowed

Note: allowedRefererDomains is a best-effort browser-side signal enforced by validateReferer() for hotlinking protection, not a strong authentication guarantee. When allowedRefererDomains is non-empty, validateReferer() blocks requests only when a Referer is present and not allowed; requests without a Referer (for example, server-to-server calls or privacy-stripping browser policies) are intentionally allowed. For strict caller validation, use short-lived signed URLs. See Referer Security Model for details.

Wildcard Syntax

Wildcard entries use the * prefix to match all subdomains:

EntryMatchesDoes NOT Match
https://example.comexample.com and all subdomains (Image Sources only)Subdomain matching in Authorized Websites
https://*.example.comcdn.example.com, img.example.com, example.com (required for subdomain matching in Authorized Websites)other-site.com
https://cdn.example.comcdn.example.com onlyimg.example.com

Wildcard semantics differ by scope: for Image Sources, https://example.com includes subdomains automatically (for example, it allows https://cdn.example.com/photo.jpg); for Authorized Websites, subdomains are not implied, so use https://*.example.com when you need to allow referers like https://app.example.com/page (while https://example.com alone only matches that exact host).

Practical Example

Project: my-company
  allowedSourceDomains: [https://cdn.site-a.com, https://images.site-b.com, https://s3.amazonaws.com]
  allowedRefererDomains: [https://app.site-a.com, https://*.site-b.com]

All API keys in this project share the same domain restrictions. Different keys are used for credential rotation and access control — not for domain segmentation.

Environment-Specific Configuration

EnvironmentImage SourcesAuthorized Websites
DevelopmentEmpty list (allows all sources for convenience)Empty list (allows all)
StagingSame as productionAdd your staging domain (https://staging.example.com)
ProductionExplicitly list all allowed originsExplicitly list all allowed websites

In production, an empty allowedSourceDomains list rejects all requests (fail-closed). Always add at least one domain before going live.

Troubleshooting

ErrorCommon CauseSolution
403 Source domain not allowedImage origin not in project's allowed sourcesAdd the domain (with https:// prefix) in Dashboard → Settings → Domain Security → Image Sources
403 Invalid refererYour website not in allowed referer listAdd your domain in Dashboard → Settings → Domain Security → Authorized Websites
403 on images that formerly workedDomain settings changed or cache propagation delayWait ~60s for settings to propagate; verify domains are still listed
Images work in development but not productionEmpty source list allows all in dev, rejects all in prodAdd explicit domains for production

Common Mistakes

  • Missing protocol — Entries must include https:// (e.g., https://cdn.example.com, not cdn.example.com)
  • Trailing slashes — Do not include trailing slashes (use https://cdn.example.com, not https://cdn.example.com/)
  • Port numbers — In allowedRefererDomains, list only the hostname (for example, use http://localhost with host localhost, not http://localhost:3000) because validateReferer() compares refererUrl.hostname (ports are ignored). If you need port-specific matching, update validateReferer() to compare refererUrl.host (or add explicit port-aware logic).

Last updated on

On this page