Skip to content

Commit

Permalink
Add guard rails to protect against undefined values in aws-ts-pulumi-…
Browse files Browse the repository at this point in the history
…webhooks
  • Loading branch information
stack72 committed Dec 10, 2019
1 parent ff34f8f commit 0600148
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions aws-ts-pulumi-webhooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ const stackConfig = {

// Just logs information from an incoming webhook request.
function logRequest(req: awsx.apigateway.Request) {
const webhookID = req.headers["pulumi-webhook-id"];
const webhookKind = req.headers["pulumi-webhook-kind"];
const webhookID = req.headers !== undefined ? req.headers["pulumi-webhook-id"] : "";
const webhookKind = req.headers !== undefined ? req.headers["pulumi-webhook-kind"] : "";
console.log(`Received webhook from Pulumi ${webhookID} [${webhookKind}]`);
}

// Webhooks can optionally be configured with a shared secret, so that webhook handlers like this app can authenticate
// message integrity. Rejects any incoming requests that don't have a valid "pulumi-webhook-signature" header.
function authenticateRequest(req: awsx.apigateway.Request): awsx.apigateway.Response | undefined {
const webhookSig = req.headers["pulumi-webhook-signature"];
const webhookSig = req.headers !== undefined ? req.headers["pulumi-webhook-signature"] : "";
if (!stackConfig.sharedSecret || !webhookSig) {
return undefined;
}
Expand Down Expand Up @@ -65,7 +65,7 @@ const webhookHandler = new awsx.apigateway.API("pulumi-webhook-handler", {
return authenticateResult;
}

const webhookKind = req.headers["pulumi-webhook-kind"];
const webhookKind = req.headers !== undefined ? req.headers["pulumi-webhook-kind"] : "";
const payload = req.body!.toString();
const parsedPayload = JSON.parse(payload);
const prettyPrintedPayload = JSON.stringify(parsedPayload, null, 2);
Expand Down

0 comments on commit 0600148

Please sign in to comment.