Skip to content

Commit e79c40c

Browse files
jongallowayCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot <[email protected]>
1 parent 1f470b6 commit e79c40c

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/NLWebNet/Middleware/NLWebMiddleware.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task InvokeAsync(HttpContext context)
3939
});
4040

4141
// Log incoming request with structured data
42-
_logger.LogInformation("Processing {Method} {Path} from {RemoteIP} with correlation ID {CorrelationId}",
42+
_logger.LogDebug("Processing {Method} {Path} from {RemoteIP} with correlation ID {CorrelationId}",
4343
context.Request.Method, context.Request.Path,
4444
context.Connection.RemoteIpAddress?.ToString() ?? "unknown", correlationId);
4545

@@ -70,7 +70,17 @@ public async Task InvokeAsync(HttpContext context)
7070

7171
private static void AddCorsHeaders(HttpContext context)
7272
{
73-
context.Response.Headers.Append("Access-Control-Allow-Origin", "*");
73+
var allowedOrigins = Environment.GetEnvironmentVariable("ALLOWED_ORIGINS")?.Split(',') ?? new[] { "*" };
74+
var origin = context.Request.Headers["Origin"].FirstOrDefault();
75+
76+
if (origin != null && allowedOrigins.Contains(origin, StringComparer.OrdinalIgnoreCase))
77+
{
78+
context.Response.Headers.Append("Access-Control-Allow-Origin", origin);
79+
}
80+
else if (allowedOrigins.Contains("*"))
81+
{
82+
context.Response.Headers.Append("Access-Control-Allow-Origin", "*");
83+
}
7484
context.Response.Headers.Append("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
7585
context.Response.Headers.Append("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Correlation-ID, X-Client-Id");
7686
context.Response.Headers.Append("Access-Control-Expose-Headers", "X-Correlation-ID, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset");

src/NLWebNet/Middleware/RateLimitingMiddleware.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public async Task InvokeAsync(HttpContext context)
4747

4848
// Add rate limit headers
4949
var status = await _rateLimitingService.GetRateLimitStatusAsync(identifier);
50-
context.Response.Headers.Append("X-RateLimit-Limit", _options.RequestsPerWindow.ToString());
51-
context.Response.Headers.Append("X-RateLimit-Remaining", status.RequestsRemaining.ToString());
52-
context.Response.Headers.Append("X-RateLimit-Reset", ((int)status.WindowResetTime.TotalSeconds).ToString());
50+
context.Response.Headers["X-RateLimit-Limit"] = _options.RequestsPerWindow.ToString();
51+
context.Response.Headers["X-RateLimit-Remaining"] = status.RequestsRemaining.ToString();
52+
context.Response.Headers["X-RateLimit-Reset"] = ((int)status.WindowResetTime.TotalSeconds).ToString();
5353

5454
await _next(context);
5555
}

0 commit comments

Comments
 (0)