-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom request transformation in AppGateway that blocks all publi…
…c traffic to */internal-api/*
- Loading branch information
Showing
3 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
application/AppGateway/Transformations/BlockInternalApiTransform.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Yarp.ReverseProxy.Transforms; | ||
|
||
namespace PlatformPlatform.AppGateway.Transformations; | ||
|
||
public class BlockInternalApiTransform : RequestTransform | ||
{ | ||
public override async ValueTask ApplyAsync(RequestTransformContext context) | ||
{ | ||
if (context.HttpContext.Request.Path.Value?.Contains("/internal-api/", StringComparison.OrdinalIgnoreCase) == true) | ||
{ | ||
context.HttpContext.Response.StatusCode = StatusCodes.Status403Forbidden; | ||
context.HttpContext.Response.ContentType = "text/plain"; | ||
await context.HttpContext.Response.WriteAsync("Access to internal API is forbidden."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters