question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AspNetCoreServer: HTTP API v2 integration double escaped URL parameters

See original GitHub issue

Description

AspNetCoreServer.APIGatewayHttpApiV2ProxyFunction URL-escapes the query string, but since it is receiving the raw, escaped query string from the API gateway this will result in a double escaping. MVC strips out one level of escaping, but that means that the web API controllers get escaped values rather than unescaped values.

This is done here in the code: https://github.com/aws/aws-lambda-dotnet/blob/master/Libraries/src/Amazon.Lambda.AspNetCoreServer/Internal/Utilities.cs#L121-L148

I have verified with a minimal Python lambda that just returns the 2.0 event as a JSON response that the query string in the event is already escaped.

Reproduction Steps

Test performed with a minimal controller based on serverless.AspNetCoreWebAPI but adapted to use HTTP API v2 instead.

Entry point:

public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayHttpApiV2ProxyFunction
{
    protected override void Init(IWebHostBuilder builder)
    {
        builder.UseStartup<Startup>();
    }
}

Controller:

[Route("api/[controller]")]
public class ValuesController : ControllerBase
{
    // GET api/values
    [HttpGet]
    public IActionResult Get([FromQuery] string a)
    {
        return Ok(new
        {
            A = a,
            RawQuery = Request.QueryString.ToString(),
        });
    }
}

Setting up a HTTP v2 integration and calling it with /api/values?a=b%3Dc produces the following output:

{ 
  "a": "b%3Dc", 
  "rawQuery" : "?a=b%253Dc"
}

The expected output is that a should have the unescaped value b=c.

Environment

Build Version:

<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.3.100.1" />
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="5.1.1" />

Targeted .NET Platform: Native .NET Core 3.1 runtime

Resolution

  • 👋 I can/would-like-to implement a fix for this problem myself

This is a 🐛 bug-report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
petlicommented, Aug 19, 2020

I’ve found a workaround for this by overriding the query string directly from the event after it has been converted by APIGatewayHttpApiV2ProxyFunction:

public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayHttpApiV2ProxyFunction
{
    // any other setup ...

    protected override void PostMarshallRequestFeature(IHttpRequestFeature aspNetCoreRequestFeature,
        APIGatewayHttpApiV2ProxyRequest lambdaRequest, ILambdaContext lambdaContext)
    {
        if (!string.IsNullOrWhiteSpace(lambdaRequest.RawQueryString))
        {
            aspNetCoreRequestFeature.QueryString = "?" + lambdaRequest.RawQueryString;
        }
    }
}
1reaction
normjcommented, Apr 5, 2021

PR has been released as part of version 6.0.0 of Amazon.Lambda.AspNetCoreServer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET MVC URL Parameters Double Escaped?
It turns out the problem lay in the textarea itself. In the view it was just a standard textarea , but in Javascript...
Read more >
URL escape codes
URL escape codes for characters that must be escaped lists the characters that must be escaped in URLs. If you must escape a...
Read more >
Set up Lambda proxy integrations in API Gateway
Understand API Gateway Lambda proxy integration; Support for multi-value headers and query string parameters; Set up a proxy resource with Lambda proxy ...
Read more >
URL in module communication is not encoding properly
We've tried using the built-in IML functions encodeURL() and decodeURL() as well as toString(), but none return the correct URL for this 2nd ......
Read more >
Guide to Java URL Encoding/Decoding
In this tutorial, we'll focus on how to encode/decode the URL or form data so that it adheres to the spec and transmits...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found