make a simple blocklist for discord + bots
This commit is contained in:
parent
07881e907d
commit
b0492e7d58
@ -5,6 +5,14 @@
|
||||
exports.handler = async function(context, event, callback) {
|
||||
const response = new Twilio.Response();
|
||||
|
||||
const blockPath = Runtime.getFunctions()['common/blockUserAgent'].path;
|
||||
const block = require(blockPath);
|
||||
|
||||
if (block.shouldBlockRequest(event)) {
|
||||
response.setStatusCode(200);
|
||||
return callback(null, response);
|
||||
}
|
||||
|
||||
let door = event.door;
|
||||
let pin = event.key;
|
||||
|
||||
|
||||
@ -6,6 +6,14 @@
|
||||
exports.handler = async function(context, event, callback) {
|
||||
const response = new Twilio.Response();
|
||||
|
||||
const blockPath = Runtime.getFunctions()['common/blockUserAgent'].path;
|
||||
const block = require(blockPath);
|
||||
|
||||
if (block.shouldBlockRequest(event)) {
|
||||
response.setStatusCode(200);
|
||||
return callback(null, response);
|
||||
}
|
||||
|
||||
let door = event.door;
|
||||
let approvalId = event.approvalId;
|
||||
let newConfig = event.newConfig;
|
||||
|
||||
@ -5,6 +5,14 @@
|
||||
exports.handler = async function(context, event, callback) {
|
||||
const response = new Twilio.Response();
|
||||
|
||||
const blockPath = Runtime.getFunctions()['common/blockUserAgent'].path;
|
||||
const block = require(blockPath);
|
||||
|
||||
if (block.shouldBlockRequest(event)) {
|
||||
response.setStatusCode(200);
|
||||
return callback(null, response);
|
||||
}
|
||||
|
||||
const door = event.door;
|
||||
|
||||
if (!door) {
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Helper method to BLOCK discordbot from scraping API links
|
||||
* This is a bit of a hack until we process event links from UI instead of raw API
|
||||
*/
|
||||
exports.shouldBlockRequest = (event) => {
|
||||
let headers = event?.request?.headers;
|
||||
let userAgentString = "";
|
||||
|
||||
if (headers && headers['user-agent']) {
|
||||
userAgentString = headers['user-agent'];
|
||||
}
|
||||
|
||||
console.log("[BlockUserAgent] got useragent", userAgentString);
|
||||
|
||||
let blockList = ["Discord", "bot", "facebook"];
|
||||
|
||||
console.log("[BlockUserAgent] blocked useragents are", blockList);
|
||||
|
||||
let willBlock = blockList.some(term => userAgentString.includes(term));
|
||||
|
||||
console.log("[BlockUserAgent] should block request: ", willBlock);
|
||||
return willBlock;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user