diff --git a/Makefile b/Makefile index d40964a..01ebc08 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,10 @@ debs := python3 python3-dev python3-pip p7zip-full golang-go msitools wget aria2 rpms := python3 python3-devel p7zip golang msitools wget aria2 pacman := python python-pip p7zip go msitools wget aria2 -.PHONY: help fetch setup setup-minimal clean set-target distclean build package build-launcher check-arch revert edits run bootstrap mozbootstrap dir package-linux package-macos package-windows vcredist_arch patch unpatch workspace check-arg +.PHONY: help fetch setup setup-minimal clean set-target distclean build package \ + build-launcher check-arch revert edits run bootstrap mozbootstrap dir \ + package-linux package-macos package-windows vcredist_arch patch unpatch \ + workspace check-arg edit-cfg ff-dbg help: @echo "Available targets:" @@ -28,6 +31,8 @@ help: @echo " package-macos - Package Camoufox for macOS" @echo " package-windows - Package Camoufox for Windows" @echo " run - Run Camoufox" + @echo " edit-cfg - Edit camoufox.cfg" + @echo " ff-dbg - Setup vanilla Firefox with minimal patches" @echo " patch - Apply a patch" @echo " unpatch - Remove a patch" @echo " workspace - Sets the workspace to a patch, assuming its applied" @@ -59,6 +64,14 @@ setup: setup-minimal git commit -m "Initial commit" && \ git tag -a unpatched -m "Initial commit" +ff-dbg: setup + # Only apply patches to help debug vanilla Firefox + make patch ./patches/chromeutil.patch + make patch ./patches/debug-url-navigation.patch + echo "\nLOCAL_INCLUDES += ['/camoucfg']" >> $(cf_source_dir)/dom/base/moz.build + touch $(cf_source_dir)/_READY + make checkpoint + revert: cd $(cf_source_dir) && git reset --hard unpatched @@ -80,7 +93,7 @@ bootstrap: dir make mozbootstrap diff: - @cd $(cf_source_dir) && git diff + @cd $(cf_source_dir) && git diff $(_ARGS) checkpoint: cd $(cf_source_dir) && git commit -m "Checkpoint" -a -uno @@ -159,10 +172,16 @@ run-pw: --release $(release) run: - CAMOU_CONFIG='{"debug": true}' \ cd $(cf_source_dir) \ && rm -rf ~/.camoufox $(cf_source_dir)/obj-x86_64-pc-linux-gnu/tmp/profile-default \ - && ./mach run $(args) + && CAMOU_CONFIG='{"debug": true}' ./mach run $(args) + +edit-cfg: + @if [ ! -f $(cf_source_dir)/obj-x86_64-pc-linux-gnu/dist/bin/camoufox.cfg ]; then \ + echo "Error: camoufox.cfg not found. Apply config.patch first."; \ + exit 1; \ + fi + $(EDITOR) $(cf_source_dir)/obj-x86_64-pc-linux-gnu/dist/bin/camoufox.cfg check-arg: @if [ -z "$(_ARGS)" ]; then \ @@ -186,7 +205,7 @@ workspace: else \ echo "Patch is not applied. Proceeding with application..."; \ fi - make checkpoint || true + make checkpoint || trueZ make patch $(_ARGS) vcredist_arch := $(shell echo $(arch) | sed 's/x86_64/x64/' | sed 's/i686/x86/') diff --git a/README.md b/README.md index 67eeef9..b3db436 100644 --- a/README.md +++ b/README.md @@ -600,7 +600,10 @@ if __name__ == "__main__": --- -## Build System +> [!NOTE] +> The content below is intended for those interested in building & debugging Camoufox. For Playwright usage instructions, see [here](https://github.com/daijro/camoufox/tree/main/pythonlib#camoufox-python-interface). + +

Build System

### Overview @@ -765,6 +768,50 @@ Patches can be edited, created, removed, and managed through here. --- +## Leak Debugging + +This is a flow chart demonstrating my process for determining leaks without deobfuscating WAF Javascript. The method incrementally reintroduces Camoufox's features into Firefox's source code until the testing site flags. + +This process requires a Linux system and assumes you have Firefox build tools installed (see [here](https://github.com/daijro/camoufox?tab=readme-ov-file#build-cli)). + +
+ +See flow chart... + + +```mermaid +flowchart TD + A[Start] --> B[Does website flag in the official Firefox?] + B -->|Yes| C[Likely bad IP/rate-limiting. If the website fails on both headless and headful mode on the official Firefox distribution, the issue is not with the browser.] + B -->|No| D["Run make ff-dbg(1) and build(2) a clean distribution of Firefox. Does the website flag in Firefox **headless** mode(4)?"] + D -->|Yes| E["Does the website flag in headful mode(3) AND headless mode(4)?"] + D -->|No| F["Open the developer UI(5), apply config.patch, then rebuild(2). Does the website still flag(3)?"] + E -->|No| G["Enable privacy.resistFingerprinting in the config(6). Does the website still flag(3)?"] + E -->|Yes| C + G -->|No| H["In the config(6), enable FPP and start omitting overrides until you find the one that fixed the leak."] + G -->|Yes| I[If you get to this point, you may need to deobfuscate the Javascript behind the website to identify what it's testing.] + F -->|Yes| K["Open the developer UI, apply the playwright bootstrap patch, then rebuild. Does it still flag?"] + F -->|No| J["Omit options from camoufox.cfg(6) and rerun(3) until you find the one causing the leak."] + K -->|No| M[Juggler needs to be debugged to locate the leak.] + K -->|Yes| L[The issue has nothing to do with Playwright. Apply the rest of the Camoufox patches one by one until the one causing the leak is found.] + M --> I +``` + +#### Cited Commands + +| # | Command | Description | +| --- | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | +| (1) | `make ff-dbg` | Setup vanilla Firefox with minimal patches. | +| (2) | `make build` | Build the source code. | +| (3) | `make run` | Runs the built browser. | +| (4) | `make run args="--headless https://test.com"` | Run a URL in headless mode. All redirects will be printed to the console to determine if the test passed. | +| (5) | `make edits` | Opens the developer UI. Allows the user to apply/undo patches, and see which patches are currently applied. | +| (6) | `make edit-cfg` | Edit camoufox.cfg in the default system editor. | + +
+ +--- + ## Thanks - [LibreWolf](https://gitlab.com/librewolf-community/browser/source) - Debloat patches & build system inspiration diff --git a/patches/xmas-modified.patch b/patches/config.patch similarity index 100% rename from patches/xmas-modified.patch rename to patches/config.patch diff --git a/patches/debug-url-navigation.patch b/patches/debug-url-navigation.patch index a393723..50add53 100644 --- a/patches/debug-url-navigation.patch +++ b/patches/debug-url-navigation.patch @@ -1,13 +1,14 @@ diff --git a/browser/base/content/browser-init.js b/browser/base/content/browser-init.js -index cc7fa914c0..760a95487e 100644 +index bee5309c04..3d0df30224 100644 --- a/browser/base/content/browser-init.js +++ b/browser/base/content/browser-init.js -@@ -257,6 +257,21 @@ var gBrowserInit = { +@@ -246,6 +246,22 @@ var gBrowserInit = { // Update UI if browser is under remote control. gRemoteControl.updateVisualCue(); + // Camoufox: print URL changes to console + if (ChromeUtils.isCamouDebug()) { ++ ChromeUtils.camouDebug("Debug mode ON."); + gBrowser.addTabsProgressListener({ + onLocationChange(aBrowser, aWebProgress, aRequest, aLocation, aFlags) { + if (aBrowser === gBrowser.selectedBrowser) {