Skip to content

URL query is not decoded when using ALB #90

@andrew0

Description

@andrew0

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

all

Plugin version

2.0.2

Node.js version

14

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

not applicable

Description

When using Lambda as a target for an ALB, the queryStringParameters in the Lambda event is not decoded, unlike with API Gateway. This isn't really well documented, but there's a small section in the docs that mentions this (not really sure why they put it under the "multi-value headers" section, but it applies to the queryStringParameters and multiValueQueryStringParameters properties):

If the query parameters are URL-encoded, the load balancer does not decode them. You must decode them in your Lambda function.

Steps to Reproduce

This test fails:

test('GET with encoded query values', async (t) => {
  t.plan(1)

  const app = fastify()
  app.get('/test', async (request, reply) => {
    reply.send(request.query)
  })
  const proxy = awsLambdaFastify(app)

  const ret = await proxy({
    requestContext: {
      elb: {
        targetGroupArn: 'xxx'
      }
    },
    httpMethod: 'GET',
    path: '/test',
    queryStringParameters: {
      q: 'foo%3Fbar'
    }
  }))
  t.equal(ret.body, '{"q":"foo?bar"}')
})

Expected Behavior

When the Lambda is invoked by ALB (detectable by presence of requestContext.elb object on event), the values for queryStringParameter and multiValueQueryStringParameters should be decoded before being passed to fastify.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions