File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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- } ;
243235app . Use ( async ( ctx , next ) =>
244236{
245237 var method = ctx . Request . Method ;
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" ) ;
You can’t perform that action at this time.
0 commit comments