-
Notifications
You must be signed in to change notification settings - Fork 4
Add Enterprise Telemetry #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gcp
wants to merge
39
commits into
enterprise-main
Choose a base branch
from
pr152-review-fixes
base: enterprise-main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,223
−24
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
9421be6
WIP
gcp 2b550e0
feat: add enterprise download security telemetry with MOZ_ENTERPRISE …
gcp 8809673
feat: add enterprise download telemetry with policy controls
gcp c1320f0
chore: update Cargo.lock
gcp f2d2f34
feat: add TELEMETRY_ENDPOINT env var support for telemetry endpoints
gcp 65a3b54
refactor: unify TELEMETRY_ENDPOINT handling across components
gcp f4ea991
refactor: use lazy loading for DownloadsTelemetry
gcp ce4144c
feat: prioritize TELEMETRY_ENDPOINT env var over localhost config
gcp a63c1a4
feat: add debug logging for download telemetry
gcp a2de78c
fix: Improve error handling and resource path resolution in downloads…
gcp 14d45c0
feat: wrap file_downloaded telemetry in MOZ_ENTERPRISE ifdef
gcp 3375a4b
fix: use MOZ_TELEMETRY_REPORTING instead of MOZILLA_OFFICIAL for tele…
gcp bab476a
feat: reset telemetry localhost port and expose MOZ_TELEMETRY_REPORTI…
gcp 2ae0626
refactor: move download telemetry to dedicated enterprise ping
gcp 7424422
fix: use PathUtils as global instead of importing as ES module
gcp b6ccae4
POC metric for page printed
46a4182
Update metric to have better data
df91afa
Put print telemetry behind #ifdef MOZ_ENTERPRISE
d69de77
Add and check prefs for metric
e19eb0e
Add content titles to print metric payload
dd5339f
Add existing add-on install metric to enterprise pings
ce37555
Include info section in enterprise ping so console can consume
c88d4ee
Allow enterprise prefix policies to be set via policy
d6ac473
Add metric for browsing a blocked URL
dfb579c
Remove debugging force-enable of download telemetry
761023b
Add policy and pref for telemetry of browsing blocked domains
f296748
Protect against telemetry exceptions for printing
4fb474d
Protect against telemetry exceptions during website filtering
d74c637
Add BlocklistDomainBrowsedTelemetry policy to schema
66b7494
Revert defunct changes to redirect telemetry
f67948c
Remove defunct cargo dependency on local glean
deec333
Remove obsolete pref
d0cda41
Remove trace log statements
ec73f3d
Address PR #152 review comments
gcp 0ff3862
Rename and restructure download telemetry metrics
gcp 0347d53
Add configurable FileLogging policy for download telemetry
gcp 3c8f6af
Fix linting issues in download telemetry tests
gcp 1726c8b
Enable enterprise download telemetry by default for local testing
gcp 9f6d06f
Remove unused enterprise prefix from Preferences policy
gcp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
264 changes: 264 additions & 0 deletions
264
browser/components/downloads/DownloadsTelemetry.enterprise.sys.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,264 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| /** | ||
| * Enterprise Downloads Telemetry Implementation | ||
| * | ||
| * This module is only included in MOZ_ENTERPRISE builds and provides | ||
| * security telemetry for completed downloads. | ||
| * | ||
| * ENTERPRISE POLICY CONFIGURATION: | ||
| * ================================ | ||
| * | ||
| * The telemetry collection can be configured via enterprise policy to control | ||
| * the level of information collected. In the enterprise policies.json file: | ||
| * | ||
| * { | ||
| * "policies": { | ||
| * "DownloadTelemetry": { | ||
| * "Enabled": true, | ||
| * "UrlLogging": "full", | ||
| * "FileLogging": "full" | ||
| * } | ||
| * } | ||
| * } | ||
| * | ||
| * Configuration Options: | ||
| * - Enabled (boolean): Enable/disable download telemetry collection | ||
| * - UrlLogging (string): URL logging level with values: | ||
| * - "full" (default): Collect complete download URLs including paths and parameters | ||
| * - "domain": Collect only the hostname portion of URLs | ||
| * - "none": Do not collect any URL information | ||
| * - FileLogging (string): File information logging level with values: | ||
| * - "full" (default): Collect filename, extension, and MIME type | ||
| * - "metadata": Collect only extension and MIME type (no filename) | ||
| * - "none": Do not collect any file information | ||
| * | ||
| * SECURITY CONSIDERATIONS: | ||
| * ======================= | ||
| * | ||
| * - "full" mode provides maximum visibility for security analysis but may | ||
| * contain sensitive information in URL paths/parameters or filenames | ||
| * - "domain" and "metadata" modes balance security monitoring with privacy | ||
| * - "none" modes disable collection entirely for high-privacy environments | ||
| * | ||
| * The default "full" mode is appropriate for most enterprise environments where | ||
| * comprehensive security monitoring is prioritized. | ||
| */ | ||
|
|
||
| import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; | ||
|
|
||
| const lazy = {}; | ||
|
|
||
| XPCOMUtils.defineLazyServiceGetter( | ||
| lazy, | ||
| "gMIMEService", | ||
| "@mozilla.org/mime;1", | ||
| "nsIMIMEService" | ||
| ); | ||
|
|
||
| export const DownloadsTelemetryEnterprise = { | ||
| /** | ||
| * Checks if download telemetry is enabled via enterprise policy. | ||
| * | ||
| * @returns {boolean} True if telemetry should be collected | ||
| */ | ||
| _isEnabled() { | ||
| return Services.prefs.getBoolPref( | ||
| "browser.download.enterprise.telemetry.enabled", | ||
| true | ||
| ); | ||
| }, | ||
|
|
||
| /** | ||
| * Gets the configured URL logging level from enterprise policy preferences. | ||
| * | ||
| * @returns {string} One of: "full", "domain", "none" | ||
| */ | ||
| _getUrlLoggingPolicy() { | ||
| const urlLogging = Services.prefs.getCharPref( | ||
| "browser.download.enterprise.telemetry.urlLogging", | ||
| "full" | ||
| ); | ||
|
|
||
| // Validate policy value | ||
| if (["full", "domain", "none"].includes(urlLogging)) { | ||
| return urlLogging; | ||
| } | ||
|
|
||
| return "full"; // Default to full URL for enterprise environments | ||
| }, | ||
|
|
||
| /** | ||
| * Gets the configured file logging level from enterprise policy preferences. | ||
| * | ||
| * @returns {string} One of: "full", "metadata", "none" | ||
| */ | ||
| _getFileLoggingPolicy() { | ||
| const fileLogging = Services.prefs.getCharPref( | ||
| "browser.download.enterprise.telemetry.fileLogging", | ||
| "full" | ||
| ); | ||
|
|
||
| // Validate policy value | ||
| if (["full", "metadata", "none"].includes(fileLogging)) { | ||
| return fileLogging; | ||
| } | ||
|
|
||
| return "full"; // Default to full file info for enterprise environments | ||
| }, | ||
|
|
||
| /** | ||
| * Processes the source URL based on the configured logging policy. | ||
| * | ||
| * @param {string} sourceUrl - The original download URL | ||
| * @returns {string|null} Processed URL or null based on policy | ||
| */ | ||
| _processSourceUrl(sourceUrl) { | ||
| if (!sourceUrl) { | ||
| return null; | ||
| } | ||
|
|
||
| const policy = this._getUrlLoggingPolicy(); | ||
|
|
||
| switch (policy) { | ||
| case "none": | ||
| return null; | ||
|
|
||
| case "domain": | ||
| try { | ||
| const url = new URL(sourceUrl); | ||
| return url.hostname || null; | ||
| } catch (ex) { | ||
| return null; | ||
| } | ||
|
|
||
| case "full": | ||
| default: | ||
| return sourceUrl; | ||
| } | ||
| }, | ||
|
|
||
| /** | ||
| * Processes file information based on the configured logging policy. | ||
| * | ||
| * @param {string} filename - The filename (basename) | ||
| * @param {string} extension - The file extension | ||
| * @param {string} mimeType - The MIME type | ||
| * @returns {object} Object with filename, extension, and mime_type based on policy | ||
| */ | ||
| _processFileInfo(filename, extension, mimeType) { | ||
| const policy = this._getFileLoggingPolicy(); | ||
|
|
||
| switch (policy) { | ||
| case "none": | ||
| return { | ||
| filename: "", | ||
| extension: "", | ||
| mime_type: "", | ||
| }; | ||
|
|
||
| case "metadata": | ||
| // Only log extension and MIME type, no filename | ||
| return { | ||
| filename: "", | ||
| extension: extension || "", | ||
| mime_type: mimeType || "", | ||
| }; | ||
|
|
||
| case "full": | ||
| default: | ||
| return { | ||
| filename: filename || "", | ||
| extension: extension || "", | ||
| mime_type: mimeType || "", | ||
| }; | ||
| } | ||
| }, | ||
|
|
||
| /** | ||
| * Records a telemetry event for a completed file download. | ||
| * | ||
| * @param {object} download - The Download object containing download information | ||
| */ | ||
| recordFileDownloaded(download) { | ||
| // Check if telemetry is enabled via enterprise policy | ||
| const isEnabled = this._isEnabled(); | ||
| if (!isEnabled) { | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| // Extract filename from target path | ||
| let filename = null; | ||
| if (download.target?.path) { | ||
| try { | ||
| // PathUtils is available as a global WebIDL binding in this context. | ||
| filename = PathUtils.filename(download.target.path); | ||
| } catch (pathErr) { | ||
| console.warn( | ||
| `[DownloadsTelemetryEnterprise] PathUtils failed, falling back to split:`, | ||
| pathErr | ||
| ); | ||
| const parts = download.target.path.split(/[/\\]/); | ||
| filename = parts[parts.length - 1] || ""; | ||
| } | ||
| } | ||
|
|
||
| // Extract file extension | ||
| let extension = null; | ||
| if (filename) { | ||
| const lastDotIndex = filename.lastIndexOf("."); | ||
| if (lastDotIndex > 0) { | ||
| extension = filename.substring(lastDotIndex + 1).toLowerCase(); | ||
| } | ||
| } | ||
|
|
||
| // Use provided content type; avoid MIME service lookup when unavailable. | ||
| let mimeType = download.contentType || ""; | ||
|
|
||
| // Process file information based on enterprise policy configuration | ||
| const fileInfo = this._processFileInfo(filename, extension, mimeType); | ||
|
|
||
| // Process source URL based on enterprise policy configuration | ||
| let sourceUrl = this._processSourceUrl(download.source?.url); | ||
|
|
||
| // Get file size | ||
| let sizeBytes = download.target?.size; | ||
| if (typeof sizeBytes !== "number" || sizeBytes < 0) { | ||
| sizeBytes = null; | ||
| } | ||
|
|
||
| const telemetryData = { | ||
| filename: fileInfo.filename, | ||
| extension: fileInfo.extension, | ||
| mime_type: fileInfo.mime_type, | ||
| size_bytes: sizeBytes, | ||
| source_url: sourceUrl || "", | ||
| is_private: download.source?.isPrivate || false, | ||
| }; | ||
|
|
||
| // Record the Glean event | ||
| Glean.downloads.downloadCompleted.record(telemetryData); | ||
|
|
||
| // Submit the enterprise ping | ||
| GleanPings.enterprise.submit(); | ||
| } catch (ex) { | ||
| // Silently fail - telemetry errors should not break downloads | ||
| console.error( | ||
| `[DownloadsTelemetryEnterprise] Download telemetry recording failed:`, | ||
| ex | ||
| ); | ||
| try { | ||
| ChromeUtils.reportError(`Download telemetry recording failed: ${ex}`); | ||
| } catch (reportEx) { | ||
| // ChromeUtils.reportError may not be available in all contexts | ||
| console.error( | ||
| `[DownloadsTelemetryEnterprise] Could not report error:`, | ||
| reportEx | ||
| ); | ||
| } | ||
| } | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| /** | ||
| * Shim module for Downloads Telemetry. | ||
| * | ||
| * This module provides a stable import path for downloads telemetry functionality. | ||
| * The actual implementation is conditionally provided at build time: | ||
| * - In MOZ_ENTERPRISE builds: Full enterprise telemetry implementation | ||
| * - In regular builds: No-op implementation (enterprise code completely absent) | ||
| */ | ||
|
|
||
| let DownloadsTelemetryImpl; | ||
|
|
||
| try { | ||
| // Attempt to import enterprise implementation (only available in MOZ_ENTERPRISE builds) | ||
| const { DownloadsTelemetryEnterprise } = ChromeUtils.importESModule( | ||
| "moz-src:///browser/components/downloads/DownloadsTelemetry.enterprise.sys.mjs" | ||
| ); | ||
| DownloadsTelemetryImpl = DownloadsTelemetryEnterprise; | ||
| } catch (ex) { | ||
| console.warn( | ||
| "[DownloadsTelemetry] Enterprise implementation not available, using no-op shim. Error:", | ||
| ex.message | ||
| ); | ||
| // Enterprise implementation not available, use no-op shim | ||
| DownloadsTelemetryImpl = { | ||
| recordFileDownloaded: _download => {}, | ||
| }; | ||
| } | ||
|
|
||
| export const DownloadsTelemetry = DownloadsTelemetryImpl; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we default to enabled by default? ok
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly for debugging, can flip the default later on. We did enable the other stuff by default.
CrowdStrike knows your downloads anyway :P