Problem/Motivation
Search API Decoupled endpoints are publicly accessible without domain restrictions, making it difficult to control which websites can consume the API. This can lead to unauthorized usage, increased server load, and potential security concerns for decoupled/headless architectures.
Steps to reproduce
- Create a Search API Decoupled endpoint
- Note that any domain can make requests to the endpoint
- No way to restrict access by domain/origin
Proposed resolution
Add a configurable "Allowed Domains" field to Search API endpoints that:
- Restricts access based on Origin, Referer, or Host headers
- Supports wildcard patterns (e.g.,
*.example.com,*-dev.pantheonsite.io) - Automatically strips protocols from entered URLs for convenience
- Falls back to allowing all domains when left empty (backward compatible)
Patches
For 1.0.0-alpha39: allowed-domains-per-endpoint-alpha39.patch
Adds domain restriction functionality to Search API Decoupled endpoints with wildcard support (e.g., *.example.com, *-dev.pantheonsite.io) for flexible domain matching.
User interface changes
Adds a new "Allowed domains" textarea field to the endpoint configuration form with:
- Multi-line input (one domain per line)
- Wildcard support using
* - Examples in field description
- Automatic URL parsing (strips protocols)
API changes
Adds two methods to SearchApiEndpointInterface:
getAllowedDomains(): Returns array of allowed domainssetAllowedDomains(array $domains): Sets allowed domains
Data model changes
Adds allowed_domains property to search_api_endpoint config entity (array of strings).
| Comment | File | Size | Author |
|---|---|---|---|
| domain-restriction-example.png | 175.1 KB | andysipple | |
| allowed-domains-per-endpoint-alpha39.patch | 8.98 KB | andysipple |
Issue fork search_api_decoupled-3551103
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
sourav_paulComment #3
jaydarnellComment #5
jaydarnellI've created a new version of the patch @andysipple provided in a new PR: https://git.drupalcode.org/project/search_api_decoupled/-/merge_requests...
Comment #6
a.dmitriiev commentedHi @jaydarnell thank you for creating a MR, please check my comments, there are questions regarding caching of access results and additional headers that might need to be sent with the response to avoid CORS problems.