aws-samples / aws-samples/aws-lambda-function-url-secured

Querystring handling incorrect for signature generation

オープン
#26 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
TypeScript
スター
27
フォーク
7
PR マージ指標
30日以内にマージされた PR はありません

説明

Came across the [Protecting an AWS Lambda function URL with Amazon CloudFront and Lambda@Edge](https://aws.amazon.com/blogs/compute/protecting-an-aws-lambda-function-url-with-amazon-cloudfront-and-lambdaedge/) blog post. As I attempted to leverage the auth function in a more generalized solution, I encountered issues where the signature was invalid (example: `The request signature we calculated does not match the signature you provided`). After debugging and reviewing signature generation documentation, my issues were related to function url calls with querystring values. Specifically here:

https://github.com/aws-samples/aws-lambda-function-url-secured/blob/40eb7fed7d02edbb3f3f0ff2d969ed2ff73f8d6c/src/functions/auth/auth.mjs#L40-L48

Based on the signature generation [documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html), it's important for the uri and querystrings to be handled separately for canonicalization. In order for valid signatures to be generated, I needed to change the above to something along the lines of the following where querystrings are provided to the request as a `QueryParameterBag`:
```javascript
const query = {};
for (const qs of request.querystring.split('&')) {
const pieces = qs.split('=');
query[pieces[0]] = pieces[1];
}

// build the request to sign
const req = new HttpRequest({
hostname,
path: request.uri,
query: query,
body: (request.body && request.body.data) ? Buffer.from(request.body.data, request.body.encoding) : undefined,
method: request.method,
});
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。