make a simple blocklist for discord + bots
All checks were successful
Build and push image for doorman-homeassistant / docker (push) Successful in 25s
Build and push Doorman UI / API / docker (push) Successful in 1m23s
Build and push image for doorman-homeassistant / deploy-gitainer (push) Successful in 22s

This commit is contained in:
Martin Dimitrov 2024-11-12 22:28:35 -08:00
parent 07881e907d
commit b0492e7d58
4 changed files with 47 additions and 0 deletions

View File

@ -5,6 +5,14 @@
exports.handler = async function(context, event, callback) { exports.handler = async function(context, event, callback) {
const response = new Twilio.Response(); 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 door = event.door;
let pin = event.key; let pin = event.key;

View File

@ -6,6 +6,14 @@
exports.handler = async function(context, event, callback) { exports.handler = async function(context, event, callback) {
const response = new Twilio.Response(); 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 door = event.door;
let approvalId = event.approvalId; let approvalId = event.approvalId;
let newConfig = event.newConfig; let newConfig = event.newConfig;

View File

@ -5,6 +5,14 @@
exports.handler = async function(context, event, callback) { exports.handler = async function(context, event, callback) {
const response = new Twilio.Response(); 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; const door = event.door;
if (!door) { if (!door) {

View File

@ -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;
};