sanitize phone number
All checks were successful
Build and push image for doorman-homeassistant / docker (push) Successful in 41s
Build and push Doorman UI / API / docker (push) Successful in 2m34s
Build and push image for doorman-homeassistant / deploy-gitainer (push) Successful in 6s

This commit is contained in:
Martin Dimitrov 2025-10-08 15:05:35 -07:00
parent 838ca2cb23
commit aba2aed396
3 changed files with 10 additions and 10 deletions

View File

@ -13,6 +13,7 @@ import { withMetrics } from "../../../common/DoormanHandler";
import { z } from "zod"; import { z } from "zod";
import { UserAgentHeader } from "../../../utils/blockUserAgent"; import { UserAgentHeader } from "../../../utils/blockUserAgent";
import { setResponseJson } from "../../../utils/responseUtils"; import { setResponseJson } from "../../../utils/responseUtils";
import { sanitizePhoneNumber } from "../../../utils/phoneUtils";
export const InfoRequestSchema = z.object({ export const InfoRequestSchema = z.object({
door: z.string().optional(), door: z.string().optional(),
@ -39,7 +40,7 @@ export const handler: ServerlessFunctionSignature<TwilioContext, InfoRequestTwil
const req = InfoRequestSchema.parse(event); const req = InfoRequestSchema.parse(event);
let door = req.door; let door = req.door;
const buzzer = req.buzzer?.slice(-10); const buzzer = sanitizePhoneNumber(req.buzzer);
const db = createDynaBridgeClient(context); const db = createDynaBridgeClient(context);

View File

@ -14,6 +14,7 @@ import { setResponseJson } from "../../../utils/responseUtils";
import { LOG_CALL_SK, LogCallSchema } from "../../../schema/LogCall"; import { LOG_CALL_SK, LogCallSchema } from "../../../schema/LogCall";
import crypto from "crypto"; import crypto from "crypto";
import { sanitizePhoneNumber } from "../../../utils/phoneUtils";
export const LogCallRequestSchema = z.object({ export const LogCallRequestSchema = z.object({
caller: z.string(), caller: z.string(),
@ -52,7 +53,7 @@ export const handler: ServerlessFunctionSignature<TwilioContext, LogCallRequestT
const response = new Twilio.Response(); const response = new Twilio.Response();
const req = LogCallRequestSchema.parse(event); const req = LogCallRequestSchema.parse(event);
let caller = req.caller; let caller = sanitizePhoneNumber(req.caller);
const db = createDynaBridgeClient(context); const db = createDynaBridgeClient(context);
@ -64,14 +65,6 @@ export const handler: ServerlessFunctionSignature<TwilioContext, LogCallRequestT
msg: "Onboarding is not open", msg: "Onboarding is not open",
}); });
} else { } else {
// TODO: best efforts cleanup
// console.log("Attempting best efforts cleanup of logged calls")
// const items = await db.entities.logCall.findAll();
// const toRemove = items.filter(item => item.SK === LOG_CALL_SK && !isTTLInFuture(item));
// console.log(`There are ${toRemove.length} old call logs to remove`);
// await db.entities.logCall.deleteBatch(toRemove);
// console.log("done cleaning up logged calls");
// log this caller // log this caller
const otp = getCode(caller); const otp = getCode(caller);
const logCall = LogCallSchema.parse({ const logCall = LogCallSchema.parse({

View File

@ -0,0 +1,6 @@
export const sanitizePhoneNumber = (phone?: string) => {
if (!phone) {
return "";
}
return phone.slice(-10);
};