forked from aws-samples/service-screener-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.js
30 lines (30 loc) · 975 Bytes
/
function.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function handler(event) {
var crypto = require('crypto');
var headers = event.request.headers;
// var wlist_ips = [
// "1.1.1.1",
// "2.2.2.2"
// ];
// printf "Basic $(printf 'vivsoft:TrumpT0w5r' | base64 -w 0)" | sha256sum | awk '{print$1}'
var authString = "9c06d532edf0813659ab41d26ab8ba9ca53b985296ee4584a79f34fe9cd743a4";
if (
typeof headers.authorization === "undefined" ||
crypto.createHash(
'sha256'
).update(headers.authorization.value).digest('hex') !== authString
) {
// if (
// !wlist_ips.includes(event.viewer.ip)
// ) {
return {
statusCode: 401,
statusDescription: "Unauthorized",
headers: {
"www-authenticate": { value: "Basic" },
"x-source-ip": { value: event.viewer.ip}
}
};
}
}
return event.request;
}