dherault / dherault/serverless-offline

REST API authorizer validation only allows for one identitySource header

Open
#1,674 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.3k
Forks
811
Avg merge
2d 4h
Merged PRs (30d)
3

Description

## Bug Report

Greetings! I have found that when validating REST API authorizers it only allows for one identitySource header. For caching, multiple headers are allowed.

According to [the REST API docs](https://www.serverless.com/framework/docs/providers/aws/events/apigateway):
> In this case, your identitySource could contain multiple entries for your policy cache.

**Current Behavior**

Using something like the following will fail to start:
```
events:
- http:
path: api/v1/endpoint
method: post
authorizer:
name: custom-authorizer
type: request
resultTtlInSeconds: 3600
identitySource: method.request.header.Authorization, method.request.header.AnotherHeader
```
Errors with:
```
Error: Serverless Offline only supports retrieving tokens from headers and querystring parameters (λ: custom-authorizer)
```

**Sample Code**

[Here's a link to the code](https://github.com/dherault/serverless-offline/blob/master/src/events/http/createAuthScheme.js#L273)

**Expected behavior/code**

The above example should start offline.

**Environment**

- `serverless` version: 3.28.1
- `serverless-offline` version: 12.0.4

**Possible Solution**

```
diff --git src/events/http/createAuthScheme.js src/events/http/createAuthScheme.js
index 71b56a70..37447aa0 100644
--- src/events/http/createAuthScheme.js
+++ src/events/http/createAuthScheme.js
@@ -270,7 +270,8 @@ export default function createAuthScheme(authorizerOptions, provider, lambda) {
authorizerOptions.type !== 'request' ||
authorizerOptions.identitySource
) {
- const headerRegExp = /^(method.|\$)request.header.((?:\w+-?)+\w+)$/
+ // Only validate the first of N possible headers.
+ const headerRegExp = /^(method.|\$)request.header.((?:\w+-?)+\w+).*$/
const queryStringRegExp =
/^(method.|\$)request.querystring.((?:\w+-?)+\w+)$/
```
**Additional context/Screenshots**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.