Skip to content

Commit 61d82b7

Browse files
committed
fix cipp reporting
1 parent 0f6691c commit 61d82b7

File tree

1 file changed

+18
-75
lines changed

1 file changed

+18
-75
lines changed

scripts/background.js

Lines changed: 18 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -665,33 +665,6 @@ class CheckBackground {
665665
}
666666
}
667667

668-
// CyberDrain integration - Send event to reporting server with timeout and proper POST
669-
async sendEvent(evt) {
670-
if (!this.policy?.CIPPReportingServer) return;
671-
try {
672-
const ctrl = new AbortController();
673-
const t = setTimeout(() => ctrl.abort(), 5000);
674-
const res = await fetch(
675-
this.policy.CIPPReportingServer.replace(/\/+$/, "") +
676-
"/events/cyberdrain-phish",
677-
{
678-
method: "POST",
679-
headers: { "Content-Type": "application/json" },
680-
body: JSON.stringify({
681-
ts: new Date().toISOString(),
682-
ua: navigator.userAgent,
683-
...evt,
684-
}),
685-
signal: ctrl.signal,
686-
}
687-
);
688-
clearTimeout(t);
689-
await res.text();
690-
} catch {
691-
/* best-effort */
692-
}
693-
}
694-
695668
setupEventListeners() {
696669
// Prevent duplicate listener registration
697670
if (this._listenersReady) return;
@@ -1705,8 +1678,24 @@ class CheckBackground {
17051678
this.pendingLocal.securityEvents.push(logEntry);
17061679
this.scheduleFlush();
17071680

1708-
// Send to CIPP if enabled
1709-
await this.sendToCipp(logEntry, config);
1681+
// Send to CIPP if enabled using the correct method
1682+
if (config?.enableCippReporting && config?.cippServerUrl) {
1683+
try {
1684+
await this.handleCippReport({
1685+
type: logEntry.event.type,
1686+
severity: logEntry.event.threatLevel || "medium",
1687+
timestamp: logEntry.timestamp,
1688+
url: logEntry.event.url,
1689+
reason: logEntry.event.reason || "Security event logged",
1690+
tabId: logEntry.tabId,
1691+
event: logEntry.event,
1692+
profile: logEntry.profile,
1693+
});
1694+
} catch (error) {
1695+
logger.error("Failed to send event to CIPP:", error);
1696+
// Don't fail the entire logging operation if CIPP is unavailable
1697+
}
1698+
}
17101699
}
17111700

17121701
enhanceEventForLogging(event) {
@@ -2152,52 +2141,6 @@ class CheckBackground {
21522141
};
21532142
}
21542143

2155-
// Send telemetry data to CIPP
2156-
async sendToCipp(logEntry, config) {
2157-
if (!config?.enableCippReporting || !config?.cippServerUrl) {
2158-
return; // CIPP reporting not enabled
2159-
}
2160-
2161-
try {
2162-
const cippPayload = {
2163-
timestamp: logEntry.timestamp,
2164-
source: "microsoft-365-phishing-protection",
2165-
version: chrome.runtime.getManifest().version,
2166-
event: logEntry.event,
2167-
profile: logEntry.profile,
2168-
tabId: logEntry.tabId,
2169-
type: logEntry.type,
2170-
};
2171-
2172-
// Add tenant/organization context if available
2173-
if (logEntry.profile?.isManaged) {
2174-
cippPayload.context = "managed";
2175-
}
2176-
2177-
const response = await fetch(`${config.cippServerUrl}`, {
2178-
method: "POST",
2179-
headers: {
2180-
"Content-Type": "application/json",
2181-
"User-Agent": `Microsoft365PhishingProtection/${
2182-
chrome.runtime.getManifest().version
2183-
}`,
2184-
},
2185-
body: JSON.stringify(cippPayload),
2186-
});
2187-
2188-
if (!response.ok) {
2189-
throw new Error(
2190-
`CIPP server responded with ${response.status}: ${response.statusText}`
2191-
);
2192-
}
2193-
2194-
logger.log("Successfully sent telemetry to CIPP");
2195-
} catch (error) {
2196-
logger.error("Failed to send telemetry to CIPP:", error);
2197-
// Don't fail the entire logging operation if CIPP is unavailable
2198-
}
2199-
}
2200-
22012144
// Handle CIPP reports from content script
22022145
async handleCippReport(basePayload) {
22032146
try {

0 commit comments

Comments
 (0)