Compare commits

...
3 changed files with 313 additions and 0 deletions

No files matched your search

+119
View File
@@ -0,0 +1,119 @@
# ─────────────────────────────────────────────────────────────────────────────
# password-mask-hunt.yml - TEMPORARY MEASUREMENT, not a gate.
#
# What it asks. Which character does the engine mask a password field with, as a page reads it: the scrollWidth of a password
# field of 40 "a" against the widths of 40 of each candidate character (U+25CF, U+2022, U+2731, U+273A, "*"), in Arial 16px and
# in the default font of an input. On Linux the mask is the "invisible-char" of a GTK entry, which GTK picks from a list by the
# fonts of the machine; Windows always uses U+25CF (the retail side of the question runs on the core's retail/password-mask).
#
# The engine is the candidate's (build run 46711856312 of the series, the artifact asset-linux-x86_64), the core is the commit
# that run used, the launch is the wrapper's normal one: InvisiblePlaywright(headless=True), a real window on a private Xvfb.
#
# It runs only on a push to the branch hunt/password-mask, and is deleted with that branch once the question is answered.
# ─────────────────────────────────────────────────────────────────────────────
name: password mask hunt
on:
push:
branches: [hunt/password-mask]
permissions:
contents: read
concurrency:
group: hunt-password-mask-${{ github.ref }}
cancel-in-progress: true
env:
GITHUB_TOKEN: ${{ github.token }}
ENGINE_RUN: "46711856312"
ENGINE_REPO: oss-invisible/firefox_antidetect_patch
CORE_SHA: b6d8600603d5a1a3601f1839a61cce4b7f3cdda2
jobs:
# The Ubuntu packages, from Ubuntu's archive once per runner image and list (linux-deps.yml), never by the hunt.
linux-deps-hunt:
name: linux-deps-hunt
uses: ./.github/workflows/linux-deps.yml
with:
name: hunt
packages: xvfb
playwright_wrapper_ref: ${{ github.sha }}
hunt:
name: password mask (linux, the product's Xvfb)
needs: linux-deps-hunt
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with: { fetch-depth: 1 }
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with: { python-version: '3.11' }
- name: The candidate's engine (the artifact of the series' build run)
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
name: asset-linux-x86_64
path: art
repository: ${{ env.ENGINE_REPO }}
run-id: ${{ env.ENGINE_RUN }}
github-token: ${{ github.token }}
- name: Extract and locate the engine
run: |
set -e
mkdir -p ff
set -- art/firefox-*-stealth-linux-x86_64.*
[ "$#" -eq 1 ] && [ -e "$1" ] || { echo "ERROR: expected one archive in art/, found: $*"; exit 1; }
tar xzf "$1" -C ff
chmod +x ff/firefox
echo "FF_EXE=$PWD/ff/firefox" >> "$GITHUB_ENV"
sha256sum "$1" ff/firefox
- name: Install the wrapper, then the core of the candidate (the commit of the build run)
run: |
python -m pip install --upgrade pip
export INVISIBLE_CORE_AUTOFIX=off INVISIBLE_CORE_PIN=allow
python -m pip install .
python -m pip install "playwright==$(cat scripts/playwright_pin.txt)"
python -m pip install --no-deps --force-reinstall "git+https://github.com/oss-invisible/core@$CORE_SHA"
python -m pip list 2>/dev/null | grep -i -E "invisible|playwright"
- name: The Linux packages (the run's linux-deps-hunt job, no mirror)
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
name: ${{ needs.linux-deps-hunt.outputs.artifact }}
path: /tmp/linux-deps
- name: System deps (xvfb + Firefox runtime libs; the repository of the linux-deps-hunt job)
run: |
set -euo pipefail
read -r OS VER < /tmp/linux-deps/image.txt
echo "the repository was read on $OS $VER; this runner is $ImageOS $ImageVersion"
sudo mkdir -p /tmp/linux-deps-apt/lists/partial /tmp/linux-deps-apt/parts
echo "deb [trusted=yes] file:/tmp/linux-deps ./" | sudo tee /tmp/linux-deps-apt/sources.list >/dev/null
APT="-o Dir::Etc::SourceList=/tmp/linux-deps-apt/sources.list -o Dir::Etc::SourceParts=/tmp/linux-deps-apt/parts -o Dir::State::Lists=/tmp/linux-deps-apt/lists -o Acquire::Languages=none"
sudo apt-get $APT update
sudo cp /tmp/linux-deps/*.deb /var/cache/apt/archives/
sudo apt-get $APT install -y --no-download --no-install-recommends $(cat /tmp/linux-deps/roots.txt)
- name: The security state (a fixed directory of the repository)
run: python scripts/ci_lab_security_state.py set --pin ci/security-state.pin.json
- name: The GeoIP database (made by the repository, same bytes every run)
run: python scripts/ci_lab_geoip.py build --pin ci/geoip.json
- name: Seal of the binary under test
run: |
export INVISIBLE_CORE_AUTOFIX=off INVISIBLE_CORE_PIN=allow
python -m invisible_core seal --binary "$FF_EXE" --tag firefox-72-candidate -o "$PWD/gate.seal.json"
- name: The measurement (the wrapper's normal launch, headless=True)
env:
PYTHONUNBUFFERED: "1"
run: |
export INVISIBLE_CORE_AUTOFIX=off INVISIBLE_CORE_PIN=allow
export INVISIBLE_SEAL_FILE="$PWD/gate.seal.json" INVPW_BINARY_PATH="$FF_EXE" STEALTHFOX_E2E_BINARY="$FF_EXE"
unset DISPLAY
mkdir -p "$RUNNER_TEMP/pwmask"
python -u scripts/hunt_password_mask.py --binary "$FF_EXE" --out "$RUNNER_TEMP/pwmask"
- name: Upload the record
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: password-mask-${{ github.run_id }}
path: ${{ runner.temp }}/pwmask
if-no-files-found: warn
retention-days: 30
+94
View File
@@ -0,0 +1,94 @@
"""Which character does the engine mask a password field with, as a page reads it? (a measurement on a branch of its own, not a gate)
python scripts/hunt_password_mask.py --binary PATH --out DIR [--seeds 21 4]
The launch is the product's: InvisiblePlaywright(seed=..., binary_path=..., headless=True), which on Linux is a real window on a
private virtual display (Xvfb). The page (scripts/hunt_password_mask_page.html, the same bytes as the retail capture's page) reads the
scrollWidth of a password field of 40 "a" and the widths of 40 of each candidate mask character in the same box styles, in Arial 16px
and in the default font of an input. Writes OUT/result.json: per seed the page's whole reading, plus the engine binary's sha256, the
fonts the host has and what fontconfig answers for the generic families.
"""
from __future__ import annotations
import argparse
import hashlib
import http.server
import json
import shutil
import socketserver
import subprocess
import tempfile
import threading
from pathlib import Path
PAGE = Path(__file__).resolve().parent / "hunt_password_mask_page.html"
class _Handler(http.server.SimpleHTTPRequestHandler):
def do_POST(self): # the page posts its result; the run reads window.__result, so the body is only drained
self.rfile.read(int(self.headers.get("Content-Length") or 0))
self.send_response(200)
self.send_header("Content-Length", "0")
self.end_headers()
def log_message(self, *args):
pass
def _sha256(path: Path) -> str:
h = hashlib.sha256()
with open(path, "rb") as f:
for block in iter(lambda: f.read(1 << 20), b""):
h.update(block)
return h.hexdigest()
def _run(cmd: list) -> str:
try:
return subprocess.run(cmd, capture_output=True, text=True, timeout=60).stdout.strip()
except (OSError, subprocess.SubprocessError) as exc:
return "error: %r" % (exc,)
def main() -> int:
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--binary", required=True)
ap.add_argument("--out", type=Path, required=True)
ap.add_argument("--seeds", type=int, nargs="+", default=[21, 4])
args = ap.parse_args()
args.out.mkdir(parents=True, exist_ok=True)
from invisible_playwright import InvisiblePlaywright
meta = {"binary": args.binary, "binary_sha256": _sha256(Path(args.binary)),
"fc_list_families": sorted(set(_run(["fc-list", ":", "family"]).splitlines())),
"fc_match": {name: _run(["fc-match", name]) for name in ("sans-serif", "serif", "monospace", "system-ui", "Arial")}}
with tempfile.TemporaryDirectory() as tmp:
shutil.copyfile(PAGE, Path(tmp) / "index.html")
handler = lambda *a, **k: _Handler(*a, directory=tmp, **k) # noqa: E731
with socketserver.TCPServer(("127.0.0.1", 0), handler) as server:
threading.Thread(target=server.serve_forever, daemon=True).start()
url = "http://127.0.0.1:%d/index.html?dpr1" % server.server_address[1]
results = {}
for seed in args.seeds:
with InvisiblePlaywright(seed=seed, binary_path=args.binary, headless=True) as browser:
page = browser.new_context().new_page()
page.goto(url, timeout=30_000)
page.wait_for_function("window.__result !== undefined && document.title === 'done'", timeout=30_000)
results[str(seed)] = page.evaluate("window.__result")
server.shutdown()
record = {"meta": meta, "results": results}
(args.out / "result.json").write_text(json.dumps(record, indent=1, sort_keys=True) + "\n", encoding="utf-8")
for seed, res in results.items():
if "error" in res:
print("seed %s: ERROR %s" % (seed, res["error"]))
continue
for font, r in res["fonts"].items():
print("seed %s %s: password(40a) scrollWidth=%s verdict(text_input)=%s verdict(span)=%s verdict(per_char)=%s"
% (seed, font, r["password"]["40"]["scrollWidth"], r["verdict"]["by_text_input_scrollWidth"],
r["verdict"]["by_span_width"], r["verdict"]["by_per_char"]))
return 0 if all("error" not in r for r in results.values()) else 1
if __name__ == "__main__":
raise SystemExit(main())
+100
View File
@@ -0,0 +1,100 @@
<!doctype html>
<meta charset="utf-8">
<title>password mask character, read as widths</title>
<body style="margin:0;background:#fff">
<script>
"use strict";
// Which character does an <input type=password> mask with? A page cannot read it, but it can read widths: the
// scrollWidth of a password field holding N copies of "a" is N times the advance of the mask character in the field's
// font. The same box styles hold N copies of each candidate character in a text input (scrollWidth) and in an inline span
// (getBoundingClientRect). The mask character is the candidate whose width equals the password width.
// Two fonts: Arial 16px, and the default font of an input (only the size is set). Also recorded: measureText of each
// candidate in a canvas with the same font, devicePixelRatio, the computed font-family of the input, navigator.platform.
const N = 40;
const CANDS = [["U+25CF", "●"], ["U+2022", "•"], ["U+2731", "✱"], ["U+273A", "✺"], ["*", "*"]];
const FONTS = [["arial16", "font-family:Arial;font-size:16px"], ["default16", "font-size:16px"]];
const BOX = "box-sizing:content-box;margin:0;padding:0;border:0;width:20px;height:24px;outline:0;";
const SPAN = "display:inline-block;white-space:pre;margin:0;padding:0;border:0;";
function input(type, value, font) {
const el = document.createElement("input");
el.type = type;
el.value = value;
el.setAttribute("style", BOX + font);
document.body.appendChild(el);
return el;
}
function span(text, familyCss) {
const el = document.createElement("span");
el.textContent = text;
el.setAttribute("style", SPAN + familyCss);
document.body.appendChild(el);
return el;
}
function measureFont(fontCase, font) {
const out = {};
const pw = input("password", "a".repeat(N), font);
const cs = getComputedStyle(pw);
const family = cs.fontFamily;
out.input_font_family = family;
out.input_font_size = cs.fontSize;
out.input_font = cs.font;
const spanFont = "font-family:" + family + ";font-size:16px";
// password widths with 1, 10 and N characters: per-character advance = (w[N] - w[10]) / (N - 10)
out.password = {};
for (const n of [1, 10, N]) {
const e = input("password", "a".repeat(n), font);
out.password[n] = {scrollWidth: e.scrollWidth, clientWidth: e.clientWidth};
e.remove();
}
out.password[N].scrollWidth_main = pw.scrollWidth;
out.password.per_char = (out.password[N].scrollWidth - out.password[10].scrollWidth) / (N - 10);
out.refs = {};
for (const [name, ch] of CANDS) {
const r = {};
r.text_input = {};
for (const n of [1, 10, N]) {
const e = input("text", ch.repeat(n), font);
r.text_input[n] = {scrollWidth: e.scrollWidth};
e.remove();
}
r.text_input.per_char = (r.text_input[N].scrollWidth - r.text_input[10].scrollWidth) / (N - 10);
const sp = span(ch.repeat(N), spanFont);
r.span_width = sp.getBoundingClientRect().width;
r.span_width_1 = (() => { const s1 = span(ch, spanFont); const w = s1.getBoundingClientRect().width; s1.remove(); return w; })();
sp.remove();
const c = document.createElement("canvas").getContext("2d");
c.font = (fontCase === "arial16" ? "16px Arial" : "16px " + family);
r.canvas_measureText = c.measureText(ch).width;
r.canvas_font = c.font;
out.refs[name] = r;
}
const pwWidth = out.password[N].scrollWidth;
out.verdict = {
by_text_input_scrollWidth: CANDS.map(c => c[0]).filter(k => out.refs[k].text_input[N].scrollWidth === pwWidth),
by_span_width: CANDS.map(c => c[0]).filter(k => Math.abs(out.refs[k].span_width - pwWidth) < 1),
by_per_char: CANDS.map(c => c[0]).filter(k => out.refs[k].text_input.per_char === out.password.per_char),
};
pw.remove();
return out;
}
(async () => {
let result;
try {
result = {format: "password-mask/1", n: N,
env: {userAgent: navigator.userAgent, platform: navigator.platform, devicePixelRatio: window.devicePixelRatio,
width: screen.width, height: screen.height},
fonts: {}};
for (const [fontCase, font] of FONTS) result.fonts[fontCase] = measureFont(fontCase, font);
} catch (e) {
result = {format: "password-mask/1", error: String(e && e.stack || e)};
}
window.__result = result;
const label = location.search.slice(1) || "result";
try { await fetch("/result?" + label, {method: "POST", body: JSON.stringify(result)}); } catch (e) { /* recorded in window.__result */ }
document.title = "done";
})();
</script>