Skip to content

Hmac header validation #2129

Answered by MihaZupan
forrestab asked this question in Q&A
Discussion options

You must be logged in to vote

If you already have a YARP route specific to webhooks, you can add a transform to just that route

.AddTransforms(builder =>
{
    if (builder.Route.RouteId == "myWebhookRoute")
    {
        builder.AddRequestTransform(async context =>
        {
            context.HttpContext.Request.EnableBuffering();

            if (false) // your validation
            {
                // As you're writing to the response, the proxy step will be skipped.
                context.HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
                await context.HttpContext.Response.WriteAsync("Nope");
            }
        });
    }
});

Alternatively in a middleware

app.MapReverseProxy(app 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by karelz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants