Skip to content
2 changes: 1 addition & 1 deletion scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class CheckBackground {
constructor() {
this.configManager = new ConfigManager();
this.policyManager = new PolicyManager();
this.detectionRulesManager = new DetectionRulesManager();
this.detectionRulesManager = new DetectionRulesManager(this.configManager);
this.rogueAppsManager = new RogueAppsManager();
this.webhookManager = new WebhookManager(this.configManager);
this.isInitialized = false;
Expand Down
108 changes: 91 additions & 17 deletions scripts/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,25 @@ if (window.checkExtensionLoaded) {
*/
async function loadDeveloperConsoleLoggingSetting() {
try {
// Request config from background to get merged enterprise + local config
const config = await new Promise((resolve) => {
chrome.storage.local.get(["config"], (result) => {
resolve(result.config || {});
chrome.runtime.sendMessage({ type: "GET_CONFIG" }, (response) => {
if (chrome.runtime.lastError) {
logger.log(
`[M365-Protection] Error getting config from background: ${chrome.runtime.lastError.message}`
);
// Fallback to local storage if background not available
chrome.storage.local.get(["config"], (result) => {
resolve(result.config || {});
});
} else if (!response || !response.success) {
// Fallback to local storage if response invalid
chrome.storage.local.get(["config"], (result) => {
resolve(result.config || {});
});
} else {
resolve(response.config);
}
});
});

Expand Down Expand Up @@ -5580,12 +5596,27 @@ if (window.checkExtensionLoaded) {
// Set flag to prevent DOM monitoring loops
showingBanner = true;

// Fetch branding configuration (uniform pattern: storage only, like applyBrandingColors)
// Fetch branding configuration from background to get merged config
const fetchBranding = () =>
new Promise((resolve) => {
try {
chrome.storage.local.get(["brandingConfig"], (result) => {
resolve(result?.brandingConfig || {});
chrome.runtime.sendMessage({ type: "GET_BRANDING_CONFIG" }, (response) => {
if (chrome.runtime.lastError) {
logger.log(
`[M365-Protection] Error getting branding from background: ${chrome.runtime.lastError.message}`
);
// Fallback to local storage if background not available
chrome.storage.local.get(["brandingConfig"], (result) => {
resolve(result?.brandingConfig || {});
});
} else if (!response || !response.success) {
// Fallback to local storage if response invalid
chrome.storage.local.get(["brandingConfig"], (result) => {
resolve(result?.brandingConfig || {});
});
} else {
resolve(response.branding || {});
}
});
} catch (_) {
resolve({});
Expand Down Expand Up @@ -5902,10 +5933,25 @@ if (window.checkExtensionLoaded) {
validBadgeTimeoutId = null;
}

// Load timeout configuration
// Load timeout configuration from background to get merged config
const config = await new Promise((resolve) => {
chrome.storage.local.get(["config"], (result) => {
resolve(result.config || {});
chrome.runtime.sendMessage({ type: "GET_CONFIG" }, (response) => {
if (chrome.runtime.lastError) {
logger.log(
`[M365-Protection] Error getting config from background: ${chrome.runtime.lastError.message}`
);
// Fallback to local storage if background not available
chrome.storage.local.get(["config"], (result) => {
resolve(result.config || {});
});
} else if (!response || !response.success) {
// Fallback to local storage if response invalid
chrome.storage.local.get(["config"], (result) => {
resolve(result.config || {});
});
} else {
resolve(response.config);
}
});
});

Expand Down Expand Up @@ -6281,15 +6327,28 @@ if (window.checkExtensionLoaded) {
return;
}

// Get CIPP configuration from storage
const result = await new Promise((resolve) => {
chrome.storage.local.get(["config"], (result) => {
resolve(result.config || {});
// Get CIPP configuration from background to get merged config
const config = await new Promise((resolve) => {
chrome.runtime.sendMessage({ type: "GET_CONFIG" }, (response) => {
if (chrome.runtime.lastError) {
logger.log(
`[M365-Protection] Error getting config from background: ${chrome.runtime.lastError.message}`
);
// Fallback to local storage if background not available
chrome.storage.local.get(["config"], (result) => {
resolve(result.config || {});
});
} else if (!response || !response.success) {
// Fallback to local storage if response invalid
chrome.storage.local.get(["config"], (result) => {
resolve(result.config || {});
});
} else {
resolve(response.config);
}
});
});

const config = result;

// Check if CIPP reporting is enabled and URL is configured
if (!config.enableCippReporting || !config.cippServerUrl) {
logger.debug("CIPP reporting disabled or no server URL configured");
Expand Down Expand Up @@ -6348,10 +6407,25 @@ if (window.checkExtensionLoaded) {
*/
async function applyBrandingColors() {
try {
// Get branding configuration from storage
// Get branding configuration from background to get merged config
const result = await new Promise((resolve) => {
chrome.storage.local.get(["brandingConfig"], (result) => {
resolve(result.brandingConfig || {});
chrome.runtime.sendMessage({ type: "GET_BRANDING_CONFIG" }, (response) => {
if (chrome.runtime.lastError) {
logger.log(
`[M365-Protection] Error getting branding from background: ${chrome.runtime.lastError.message}`
);
// Fallback to local storage if background not available
chrome.storage.local.get(["brandingConfig"], (result) => {
resolve(result?.brandingConfig || {});
});
} else if (!response || !response.success) {
// Fallback to local storage if response invalid
chrome.storage.local.get(["brandingConfig"], (result) => {
resolve(result?.brandingConfig || {});
});
} else {
resolve(response.branding || {});
}
});
});

Expand Down
14 changes: 10 additions & 4 deletions scripts/modules/detection-rules-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { chrome, storage } from "../browser-polyfill.js";
import logger from "../utils/logger.js";

export class DetectionRulesManager {
constructor() {
constructor(configManager = null) {
this.cachedRules = null;
this.lastUpdate = 0;
this.updateInterval = 24 * 60 * 60 * 1000; // Default: 24 hours
Expand All @@ -16,6 +16,7 @@ export class DetectionRulesManager {
this.remoteUrl =
"https://raw.githubusercontent.com/CyberDrain/Check/refs/heads/main/rules/detection-rules.json";
this.config = null;
this.configManager = configManager;
this.initialized = false;
}

Expand Down Expand Up @@ -53,9 +54,14 @@ export class DetectionRulesManager {

async loadConfiguration() {
try {
// Load from chrome storage to get user configuration
const result = await storage.local.get(["config"]);
this.config = result?.config || {};
// Use ConfigManager if available to get merged configuration (enterprise + local)
if (this.configManager) {
this.config = await this.configManager.getConfig();
} else {
// Fallback to direct storage access if ConfigManager is not available
const result = await storage.local.get(["config"]);
this.config = result?.config || {};
}

// Set remote URL from configuration or use default
if (this.config.customRulesUrl) {
Expand Down