Summary
The shipped CORS configuration does not include PATCH in CorsOptions.AllowedMethods.
However, the API exposes several PATCH endpoints, and both React clients call them. When the frontend and API are hosted on different origins with CorsOptions.AllowAll=false, the browser rejects the preflight request before it reaches the API.
This is hidden during normal local development because appsettings.Development.json sets CorsOptions.AllowAll to true, which calls AllowAnyMethod().
Where
The following files currently allow only GET, POST, PUT, and DELETE:
src/Host/FSH.Starter.Api/appsettings.json
src/Host/FSH.Starter.Api/appsettings.Production.json
The restricted CORS branch passes that list directly to:
.WithMethods(settings.AllowedMethods)
in:
src/BuildingBlocks/Web/Cors/Extensions.cs
Existing PATCH endpoints
The backend currently exposes PATCH endpoints for:
- Changing a product price
- Adjusting product stock
- Changing file visibility
- Toggling user status
Both clients/admin and clients/dashboard send requests using method: "PATCH" for these operations.
Minimal reproduction
Configure the API with a restricted CORS policy:
"CorsOptions": {
"AllowAll": false,
"AllowedOrigins": [
"http://localhost:5174"
],
"AllowedHeaders": [
"content-type",
"authorization",
"tenant"
],
"AllowedMethods": [
"GET",
"POST",
"PUT",
"DELETE"
]
}
The tenant header is included above to isolate this issue from #1367.
- Run the API.
- Run
clients/dashboard at http://localhost:5174.
- Sign in and try to change a product price or adjust its stock.
- Alternatively, try to change a file's visibility.
- Inspect the browser network panel and console.
The browser sends an OPTIONS preflight with:
Access-Control-Request-Method: PATCH
Because PATCH is absent from Access-Control-Allow-Methods, the browser blocks the request before it reaches the PATCH endpoint.
Expected behavior
Existing PATCH API calls should be allowed when the requesting origin and headers are otherwise permitted by the restricted CORS policy.
Actual behavior
Cross-origin PATCH calls are rejected during the browser's CORS preflight.
Suggested fix
Add "PATCH" to CorsOptions.AllowedMethods in both shipped configuration files:
"AllowedMethods": [
"GET",
"POST",
"PUT",
"PATCH",
"DELETE"
]
A regression test covering the restricted CORS policy would also help prevent the method list from drifting away from the API's supported methods.
Environment
- .NET SDK:
10.0.100
- Database provider: PostgreSQL
- Affected configuration:
CorsOptions.AllowAll=false
Summary
The shipped CORS configuration does not include
PATCHinCorsOptions.AllowedMethods.However, the API exposes several
PATCHendpoints, and both React clients call them. When the frontend and API are hosted on different origins withCorsOptions.AllowAll=false, the browser rejects the preflight request before it reaches the API.This is hidden during normal local development because
appsettings.Development.jsonsetsCorsOptions.AllowAlltotrue, which callsAllowAnyMethod().Where
The following files currently allow only
GET,POST,PUT, andDELETE:src/Host/FSH.Starter.Api/appsettings.jsonsrc/Host/FSH.Starter.Api/appsettings.Production.jsonThe restricted CORS branch passes that list directly to:
in:
src/BuildingBlocks/Web/Cors/Extensions.csExisting PATCH endpoints
The backend currently exposes
PATCHendpoints for:Both
clients/adminandclients/dashboardsend requests usingmethod: "PATCH"for these operations.Minimal reproduction
Configure the API with a restricted CORS policy:
The
tenantheader is included above to isolate this issue from #1367.clients/dashboardathttp://localhost:5174.The browser sends an
OPTIONSpreflight with:Access-Control-Request-Method: PATCHBecause
PATCHis absent fromAccess-Control-Allow-Methods, the browser blocks the request before it reaches thePATCHendpoint.Expected behavior
Existing
PATCHAPI calls should be allowed when the requesting origin and headers are otherwise permitted by the restricted CORS policy.Actual behavior
Cross-origin
PATCHcalls are rejected during the browser's CORS preflight.Suggested fix
Add
"PATCH"toCorsOptions.AllowedMethodsin both shipped configuration files:A regression test covering the restricted CORS policy would also help prevent the method list from drifting away from the API's supported methods.
Environment
10.0.100CorsOptions.AllowAll=false