Skip to content

Commit 2b21ed9

Browse files
committed
feat: add test environment URL to allowed origins
1 parent 24d326c commit 2b21ed9

1 file changed

Lines changed: 2 additions & 9 deletions

File tree

src/Dashboard/Program.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,6 @@
232232

233233
// CSRF defense — for state-changing requests, require Origin/Referer to match this host.
234234
// Combined with SameSite=Lax cookies this defeats the standard CSRF surface.
235-
var allowedOriginHosts = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
236-
{
237-
"azure-finops-agent.com",
238-
"www.azure-finops-agent.com",
239-
"finops-agent-container.azurewebsites.net",
240-
"localhost:5000",
241-
"localhost:5173",
242-
};
243235
app.Use(async (ctx, next) =>
244236
{
245237
var method = ctx.Request.Method;
@@ -253,7 +245,8 @@
253245
if (Uri.TryCreate(origin, UriKind.Absolute, out var oUri)) sourceHost = oUri.Authority;
254246
else if (Uri.TryCreate(referer, UriKind.Absolute, out var rUri)) sourceHost = rUri.Authority;
255247

256-
if (string.IsNullOrEmpty(sourceHost) || !allowedOriginHosts.Contains(sourceHost))
248+
var ownHost = ctx.Request.Host.Value ?? "";
249+
if (string.IsNullOrEmpty(sourceHost) || !string.Equals(sourceHost, ownHost, StringComparison.OrdinalIgnoreCase))
257250
{
258251
ctx.Response.StatusCode = 403;
259252
await ctx.Response.WriteAsync("Forbidden: cross-origin write blocked");

0 commit comments

Comments
 (0)