Skip to content

Commit 06b448c

Browse files
committed
adding a header check
1 parent 2c6cba8 commit 06b448c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

hello/server.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@ const http = require("http");
22

33
http
44
.createServer(function (request, response) {
5+
6+
//
7+
// If the app has been configured to check the CIS secret,
8+
// make sure that the request header value 'x-cis-secret' matches the configured secret.
9+
// If it doesn't match, assume that the request bypassed the CIS firewall and reject it.
10+
if(process.env.CIS_SECRET && request.headers['x-cis-secret'] !== process.env.CIS_SECRET){
11+
response.writeHead(403);
12+
return response.end();
13+
}
14+
515
//
6-
// debug endpoint, which prints all incoming headers and environment variables
16+
// Debug endpoint, which prints all incoming headers and environment variables
717
if (request.url == "/debug") {
818
const respData = {
919
headers: request.headers,
@@ -17,7 +27,7 @@ http
1727
}
1828

1929
//
20-
// default http endpoint, which prints a simple hello world
30+
// Default http endpoint, which prints a simple hello world
2131
target = process.env.TARGET ? process.env.TARGET : "World";
2232
msg = process.env.MSG ? process.env.MSG : "Hello " + target + "\n";
2333
response.writeHead(200, { "Content-Type": "text/plain" });

0 commit comments

Comments
 (0)