Securing the Node.js webhook for Dialogflow
You will now make slight modifications to the Node.js code in order to secure the webhook. The one you deployed is not secure and anyone can access it.
- Go to Dialogflow and to the
Fulfillment
section. - In the headers, add the key
mysecret
and the value12345
.
The following screenshot shows the security header added to the webhook:

Securing the webhook
- Edit
server.js
. Add code that extracts themysecret
key usinglet secret = req.get("mysecret")
. Then, check the value and see if it is equal to12345
. If it is equal, process the request, and if not, return a 403 access denied response returnresponse.status(403).end('Access denied!')
.
The following code shows the modified code that secures the webhook:
app.post('/fortuneCookie', function (req, res) { let secret = req.get("mysecret"); if(secret === "12345"){ request = req; response = res; console.log('Fortune Cookie Request headers: ' + JSON.stringify(request.headers)); console...