refactor phase 4 hardening helpers and redacted logging

This commit is contained in:
2026-03-12 09:03:24 +00:00
parent aeec5e0f59
commit a0ae6fcba3
6 changed files with 92 additions and 18 deletions
+16 -6
View File
@@ -44,6 +44,8 @@
import axios from "axios";
import CryptoJS from "crypto-js";
import _ from "lodash";
import { isNonEmptyString, sanitizeString } from "../../../actions/core/guards";
import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token";
import { getCaseBlob } from "../../../actions/azurestorage";
const WORDKEY = process.env.HASHKEY;
@@ -66,6 +68,17 @@ const hashAPIPath = (queryPath) => {
export default async function ApiProxy(req, res) {
var createTaskBody = req.body;
const contactEmail = sanitizeString(createTaskBody?.contactEmail);
const contactSubject = sanitizeString(createTaskBody?.contactSubject);
const contactBody = sanitizeString(createTaskBody?.contactbody);
if (!isNonEmptyString(contactEmail) || !isNonEmptyString(contactSubject)) {
return res.status(400).json({
error: "contactEmail and contactSubject are required"
});
}
var queryUrl = "tasks";
var token = await getToken();
@@ -87,8 +100,8 @@ export default async function ApiProxy(req, res) {
let teamId = teamMap[contactValue];
const payload = {
"subject": `Contact Us Enquiry - ${createTaskBody.contactSubject}`,
"description": `From: ${createTaskBody.contactEmail}\n\n${createTaskBody.contactbody}`,
"subject": `Contact Us Enquiry - ${contactSubject}`,
"description": `From: ${contactEmail}\n\n${contactBody}`,
"scheduledstart": new Date().toISOString(),
"scheduledend": new Date(
new Date().getTime() + 60 * 60000 * 24
@@ -118,10 +131,7 @@ export default async function ApiProxy(req, res) {
const { data } = await axios(config);
return res.status(200).json(data);
} catch (error) {
console.error(
"CRM Task Creation Error:",
error.response?.data || error
);
consoleLogger(error);
return res
.status(400)
.json({ error: "Failed to create CRM task", details: error });