Querystring handling incorrect for signature generation

Aperta
#26 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
aws, javascript

Direzione di ricerca

Inizia in src/functions/auth/auth.mjs intorno alle righe 40-48 e confronta la costruzione attuale di HttpRequest con la documentazione sulla canonicalizzazione di AWS Signature Version 4. Esegui la funzione auth con una Lambda function URL contenente parametri di query, assicurandoti che i valori URI e query vengano passati separatamente. Il lavoro è completato quando le requests con query strings producono firme valide.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Came across the Protecting an AWS Lambda function URL with Amazon CloudFront and Lambda@Edge 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, 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:

  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,
  });
Lingua principale
TypeScript
Stelle
27
Fork
7
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di aws-samples/aws-lambda-function-url-secured

Tutte le issue di aws-samples/aws-lambda-function-url-secured

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.