Skip to content

Commit

Permalink
Add config type validator
Browse files Browse the repository at this point in the history
- Validates property types passed in --config.
- Types are stored in properties.json.
  • Loading branch information
daijro committed Aug 18, 2024
1 parent c5356e9 commit a2cb02d
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ package-linux:
python3 scripts/package.py linux \
--includes \
settings/chrome.css \
settings/properties.json \
bundle/fontconfigs \
--version $(version) \
--release $(release) \
Expand All @@ -120,6 +121,7 @@ package-macos:
python3 scripts/package.py macos \
--includes \
settings/chrome.css \
settings/properties.json \
--version $(version) \
--release $(release) \
--arch $(arch) \
Expand All @@ -130,6 +132,7 @@ package-windows:
python3 scripts/package.py windows \
--includes \
settings/chrome.css \
settings/properties.json \
~/.mozbuild/vs/VC/Redist/MSVC/14.38.33135/$(vcredist_arch)/Microsoft.VC143.CRT/*.dll \
--version $(version) \
--release $(release) \
Expand Down
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,34 +151,38 @@ Screen
| screen.availWidth ||
| screen.availTop ||
| screen.availLeft ||
| screen.colorDepth ||
| screen.height ||
| screen.width ||
| screen.colorDepth ||
| screen.pixelDepth ||
| screen.pageXOffset ||
| screen.pageYOffset ||

**Notes:**

- `screen.colorDepth` and `screen.pixelDepth` are synonymous.

</details>

<details>
<summary>
Window
</summary>

| Property | Status |
| ----------------------- | --------------------------- |
| window.scrollMinX | |
| window.scrollMinY | |
| window.scrollMaxX | |
| window.scrollMaxY | |
| window.innerHeight | |
| window.outerHeight | |
| window.outerWidth | |
| window.innerWidth | |
| window.screenX | |
| window.screenY | |
| window.history.length | |
| window.devicePixelRatio | Works, but not recommended! |
| Property | Status | Notes |
| ----------------------- | ------ | ------------------------------- |
| window.scrollMinX ||
| window.scrollMinY ||
| window.scrollMaxX ||
| window.scrollMaxY ||
| window.outerHeight || Sets the window height. |
| window.outerWidth || Sets the window width. |
| window.innerHeight || Sets the inner viewport height. |
| window.innerWidth || Sets the inner viewport width. |
| window.screenX ||
| window.screenY ||
| window.history.length ||
| window.devicePixelRatio | | Works, but not recommended. |

**Notes:**

Expand Down Expand Up @@ -269,7 +273,7 @@ You can also exclude default addons with the `--exclude-addons` flag:
Miscellaneous (WebGl spoofing, battery status, etc)
</summary>

| Property | Status | Notes |
| Property | Status | Description |
| ----------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| pdfViewer || Sets navigator.pdfViewerEnabled. Please keep this on though, many websites will flag a lack of pdfViewer as a headless browser. |
| webGl:renderer || Spoofs the name of the unmasked WebGL renderer. Can cause leaks, use at your own caution! Also note, webGl is disabled in Camoufox by default. |
Expand Down
3 changes: 2 additions & 1 deletion launcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func main() {
// Read and parse the config file
var configMap map[string]interface{}
parseJson(configPath, &configMap)
validateConfig(configMap)

//*** PARSE ADDONS ***//

Expand Down Expand Up @@ -199,7 +200,7 @@ func setEnvironmentVariables(configMap map[string]interface{}, userAgentOS strin
}

if normalizeOS(runtime.GOOS) == "linux" {
fontconfigPath := filepath.Join("fontconfig", userAgentOS)
fontconfigPath := getPath(filepath.Join("fontconfig", userAgentOS))
os.Setenv("FONTCONFIG_PATH", fontconfigPath)
}
}
67 changes: 67 additions & 0 deletions launcher/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
"fmt"
"math"
"os"
"reflect"
)

type Property struct {
Property string `json:"property"`
Type string `json:"type"`
}

func validateConfig(configMap map[string]interface{}) {
properties := loadProperties()

// Create a map for quick lookup of property types
propertyTypes := make(map[string]string)
for _, prop := range properties {
propertyTypes[prop.Property] = prop.Type
}

for key, value := range configMap {
expectedType, exists := propertyTypes[key]
if !exists {
fmt.Printf("Warning: Unknown property %s in config\n", key)
continue
}

if !validateType(value, expectedType) {
fmt.Printf("Invalid type for property %s. Expected %s, got %T\n", key, expectedType, value)
os.Exit(1)
}
}
}

func loadProperties() []Property {
propertiesPath := getPath("properties.json")
var properties []Property
parseJson(propertiesPath, &properties)
return properties
}

func validateType(value interface{}, expectedType string) bool {
switch expectedType {
case "str":
_, ok := value.(string)
return ok
case "int":
v, ok := value.(float64)
return ok && v == math.Trunc(v)
case "uint":
v, ok := value.(float64)
return ok && v == math.Trunc(v) && v >= 0
case "double":
_, ok := value.(float64)
return ok
case "bool":
_, ok := value.(bool)
return ok
case "array":
return reflect.TypeOf(value).Kind() == reflect.Slice
default:
return false
}
}
3 changes: 2 additions & 1 deletion patches/xmas-modified.patch
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ diff --git a/lw/moz.build b/lw/moz.build
index e69de29bb2..208184547e 100644
--- a/lw/moz.build
+++ b/lw/moz.build
@@ -0,0 +1,13 @@
@@ -0,0 +1,14 @@
+FINAL_TARGET_FILES += [
+ "camoufox.cfg",
+ "chrome.css",
+ "properties.json"
+]
+
+FINAL_TARGET_FILES.distribution += [
Expand Down
1 change: 1 addition & 0 deletions scripts/copy-additions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ run 'cp -v ../../settings/camoufox.cfg .'
run 'cp -v ../../settings/distribution/policies.json .'
run 'cp -v ../../settings/defaults/pref/local-settings.js .'
run 'cp -v ../../settings/chrome.css .'
run 'cp -v ../../settings/properties.json .'
run 'touch moz.build'
popd > /dev/null

Expand Down
58 changes: 58 additions & 0 deletions settings/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{ "property": "navigator.userAgent", "type": "str" },
{ "property": "navigator.doNotTrack", "type": "str" },
{ "property": "navigator.appCodeName", "type": "str" },
{ "property": "navigator.appName", "type": "str" },
{ "property": "navigator.appVersion", "type": "str" },
{ "property": "navigator.oscpu", "type": "str" },
{ "property": "navigator.language", "type": "str" },
{ "property": "navigator.languages", "type": "array" },
{ "property": "navigator.platform", "type": "str" },
{ "property": "navigator.hardwareConcurrency", "type": "uint" },
{ "property": "navigator.product", "type": "str" },
{ "property": "navigator.productSub", "type": "str" },
{ "property": "navigator.maxTouchPoints", "type": "uint" },
{ "property": "navigator.cookieEnabled", "type": "bool" },
{ "property": "navigator.globalPrivacyControl", "type": "bool" },
{ "property": "navigator.buildID", "type": "str" },
{ "property": "navigator.onLine", "type": "bool" },
{ "property": "screen.availHeight", "type": "uint" },
{ "property": "screen.availWidth", "type": "uint" },
{ "property": "screen.availTop", "type": "uint" },
{ "property": "screen.availLeft", "type": "uint" },
{ "property": "screen.height", "type": "uint" },
{ "property": "screen.width", "type": "uint" },
{ "property": "screen.colorDepth", "type": "uint" },
{ "property": "screen.pixelDepth", "type": "uint" },
{ "property": "screen.pageXOffset", "type": "double" },
{ "property": "screen.pageYOffset", "type": "double" },
{ "property": "window.scrollMinX", "type": "int" },
{ "property": "window.scrollMinY", "type": "int" },
{ "property": "window.scrollMaxX", "type": "int" },
{ "property": "window.scrollMaxY", "type": "int" },
{ "property": "window.outerHeight", "type": "uint" },
{ "property": "window.outerWidth", "type": "uint" },
{ "property": "window.innerHeight", "type": "uint" },
{ "property": "window.innerWidth", "type": "uint" },
{ "property": "window.screenX", "type": "int" },
{ "property": "window.screenY", "type": "int" },
{ "property": "window.history.length", "type": "uint" },
{ "property": "window.devicePixelRatio", "type": "double" },
{ "property": "document.body.clientWidth", "type": "uint" },
{ "property": "document.body.clientHeight", "type": "uint" },
{ "property": "document.body.clientTop", "type": "uint" },
{ "property": "document.body.clientLeft", "type": "uint" },
{ "property": "headers.User-Agent", "type": "str" },
{ "property": "headers.Accept-Language", "type": "str" },
{ "property": "headers.Accept-Encoding", "type": "str" },
{ "property": "webrtc:ipv4", "type": "str" },
{ "property": "webrtc:ipv6", "type": "str" },
{ "property": "pdfViewerEnabled", "type": "bool" },
{ "property": "webGl:renderer", "type": "str" },
{ "property": "webGl:vendor", "type": "str" },
{ "property": "battery:charging", "type": "bool" },
{ "property": "battery:chargingTime", "type": "double" },
{ "property": "battery:dischargingTime", "type": "double" },
{ "property": "battery:level", "type": "double" },
{ "property": "fonts", "type": "array" }
]

0 comments on commit a2cb02d

Please sign in to comment.