allow passing wildcard domains in serverActions.allowedDomains (#59428)
Implementation of feature request opened here - https://github.com/vercel/next.js/discussions/59427 Approach: ~~We are using micromatch in the csrf protection step of actionHandler to allow for wildcard domains passed in allowedDomains. This is the same library used for matching domains for remote images.~~ If any of the allowed domains match the origin of the request, we skip the downstream error thrown for csrf protection. Edit: Micromatch is not available in this context as it is only compatible with Node. This codepath can be run from the edge, so we need to rely on vanilla js compatible code only. Instead of falling back to allowing the user to pass in a regex, which can be somewhat insecure, we opt into continuing to use a wildcard pattern from a configuration standpoint and instead use a simple function that matches on wildcards using string comparison and iteration. Ideally, Micromatch can be retrofitted to work in non-Node settings and this piece of code can be replaced in the future, without deprecating or changing the next.config interface. --------- Co-authored-by:Josh Story <story@hey.com>
Showing
Please
register
or
sign in
to comment