Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion extension/e2e/fake-host.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
(DEADBOLT_FAKE_LIST_DELAY each list reply), and
DEADBOLT_FAKE_SIGNIN adds "Sign in with Google" logins, and
DEADBOLT_FAKE_GOOGLE lists three Google logins instead of its own, and
DEADBOLT_FAKE_KEYLOGIN adds a login with no username. Saves
DEADBOLT_FAKE_KEYLOGIN adds a login with no username, and
DEADBOLT_FAKE_ONE_LINE adds an identity with its address on one line. Saves
are checked against the spec's title and URL rules. Generated passwords are held per
origin, as the daemon holds them: candidates until generate-keep, then
pending, and check and save resolve only pending ones. Fields that allow
Expand Down Expand Up @@ -59,6 +60,12 @@
VISA: {"number": "4242424242424242", "cvv": "123", "expiry": "2028-08", "cardholder": "Alex Mercer", "brand": "Visa"},
}
VALUES = {REF1: {"username": "alex@acme.test", "password": "correct horse", "totp": "492039"}, REF2: {"username": "admin", "password": "hunter2"}}
# DEADBOLT_FAKE_ONE_LINE=1 adds "Mailing", an identity that keeps its whole
# address in its first line, as one typed into a single box is saved.
if os.environ.get("DEADBOLT_FAKE_ONE_LINE"):
MAILING = "c" * 64 + ":" + "4" * 32
IDENTITIES.append({"ref": MAILING, "title": "Mailing", "summary": "Alex Mercer Β· 123 Main St, Apt 4, Brooklyn, NY, 11201, United States"})
FORM_VALUES[MAILING] = {"given-name": "Alex", "family-name": "Mercer", "address-line1": "123 Main St, Apt 4, Brooklyn, NY, 11201, United States"}
# DEADBOLT_FAKE_USERNAME and DEADBOLT_FAKE_PASSWORD replace the first login's
# values (corpus/sweep.ts, on real sites).
if os.environ.get("DEADBOLT_FAKE_USERNAME"):
Expand Down
50 changes: 45 additions & 5 deletions extension/e2e/gauntlet/scenarios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
// these its helpers.
//
// The e2e logins are the fake host's: alex@acme.test ("correct horse", with
// a one-time code) and admin ("hunter2"); the identity "Home" and the card
// "Personal Visa".
// a one-time code) and admin ("hunter2"); the identities "Home" and "Work",
// the card "Personal Visa", and for the pages that pick it "Mailing", an
// identity with its whole address on one line.

import type { BrowserContext, Frame, Page, Worker } from "playwright-core"
import { BACKUP_CODES, EMAIL_CODE, PAGES, SMS_CODE, type Account } from "./site"
Expand All @@ -20,7 +21,8 @@ export interface Harness<R extends GauntletRun> {
/** http://localhost:<port> */
site: string
port: number
launch(options?: { record?: string; scale?: number }): Promise<R>
/** `oneLine`: the vault also lists "Mailing", an identity that keeps its whole address in its first line. */
launch(options?: { record?: string; scale?: number; oneLine?: boolean }): Promise<R>
close(run: R): Promise<void>
check(ok: boolean, what: string): boolean
settled(menu: Frame): Promise<void>
Expand Down Expand Up @@ -686,6 +688,43 @@ export function gauntletScenarios<R extends GauntletRun>(h: Harness<R>): { scena
await c.page.click("#submit")
c.ok(!!(await wait("saved", async () => (await c.page.locator("#result[data-ok]").count()) > 0)), "and the form submits")
},
"mailing-address-continued": async (c) => {
const FIELDS = ["#first", "#last", "#street", "#street-more", "#city", "#country", "#state", "#zip"]
// Twice: an identity with its address in parts, then one that keeps the whole address in its first line.
for (const [title, how] of [["Home", "an identity with its address in parts"], ["Mailing", "an identity with its whole address on one line"]]) {
await c.page.goto(g("mailing-address-continued"))
c.ok(!(await c.page.isVisible("#street")), "the mailing address is hidden until Paper check is chosen")
await c.page.click("#pay-check")
await c.page.waitForSelector("#street", { state: "visible" })
c.ok((await c.page.locator("#state option").count()) === 1 && (await value(c.page, "#state")) === "0", "the state list holds only its Select placeholder, value 0")
c.ok(await pickForm(c, "#street", title), `one pick of ${how} fills`)
c.ok(await filledWith(c.page, "#state", "32", 5000), "the state is chosen once the country's states load, by its code in \"NY - New York\"")
const got = await Promise.all(FIELDS.map((s) => value(c.page, s)))
c.ok(JSON.stringify(got) === JSON.stringify(["Alex", "Mercer", "123 Main St", "Apt 4", "Brooklyn", "US", "32", "11201"]), `all eight fields, the unit in the Continued line (${got.join(" | ")})`)
c.ok(got[2].length <= 40 && got[3].length <= 40, `neither street line is over its 40 characters (${got[2].length}, ${got[3].length})`)
await c.page.click("#submit")
const saved = await wait("saved", async () => (await c.page.locator("#result[data-ok], #error").count()) > 0)
c.ok(!!saved && (await c.page.locator("#result[data-ok]").count()) > 0, `and the page takes it (${(await c.page.locator("#error").textContent({ timeout: 500 }).catch(() => "")) || "no error"})`)
}
},
"address-optional-line": async (c) => {
await c.page.goto(g("address-optional-line"))
const SHIP = ["#ship-street", "#ship-street-b", "#ship-city", "#ship-state", "#ship-zip"]
const BILL = ["#bill-street", "#bill-city", "#bill-state", "#bill-zip"]
const read = (sels: string[]) => Promise.all(sels.map((s) => value(c.page, s)))
c.ok(await pickForm(c, "#ship-street", "Home"), "one pick on the shipping street fills")
let ship = await read(SHIP)
c.ok(JSON.stringify(ship) === JSON.stringify(["123 Main St", "Apt 4", "Brooklyn", "NY", "11201"]), `both street lines and the rest of the shipping address (${ship.join(" | ")})`)
let bill = await read(BILL)
c.ok(bill.every((v) => !v), `the billing address gets 0 bytes (${bill.join(" | ")})`)
c.ok(await pickForm(c, "#bill-street", "Work"), "a pick on the billing street fills")
bill = await read(BILL)
c.ok(JSON.stringify(bill) === JSON.stringify(["1 Market St", "San Francisco", "CA", "94105"]), `the billing address, from another identity (${bill.join(" | ")})`)
ship = await read(SHIP)
c.ok(JSON.stringify(ship) === JSON.stringify(["123 Main St", "Apt 4", "Brooklyn", "NY", "11201"]), `and the shipping address is as it was (${ship.join(" | ")})`)
await c.page.click("#submit")
c.ok(!!(await wait("saved", async () => (await c.page.locator("#result[data-ok]").count()) > 0)), "and the form submits")
},
"spa-shell-save": async (c) => {
await c.page.goto(g("spa-shell-save"))
await reported(c.run, "/gauntlet/spa-shell-save")
Expand Down Expand Up @@ -747,7 +786,8 @@ export function gauntletScenarios<R extends GauntletRun>(h: Harness<R>): { scena
const only = process.env.GAUNTLET_PAGES?.split(",").filter(Boolean)
const slugs = only ? all.filter((s) => only.includes(s)) : all
if (!slugs.length) return
const run = await h.launch(h.video ? { record: h.video, scale: 1 } : {})
// The one-line identity is listed only for the pages that pick it: every other menu is as it was.
const run = await h.launch({ ...(h.video ? { record: h.video, scale: 1 } : {}), oneLine: slugs.includes("mailing-address-continued") })
try {
for (const slug of slugs) {
const page = await run.context.newPage()
Expand Down Expand Up @@ -805,6 +845,6 @@ export function gauntletScenarios<R extends GauntletRun>(h: Harness<R>): { scena
if (missing.length) throw new Error(`gauntlet pages without a scenario: ${missing.join(", ")}`)
return {
scenarios: Object.fromEntries(Object.entries(units).map(([name, slugs]) => [name, () => runPages(slugs)])),
cost: { gauntletSignIn: 38, gauntletCodes: 80, gauntletIdentity: 19, gauntletDom: 52, gauntletDom2: 50, gauntletFlows: 55, gauntletTraps: 95 },
cost: { gauntletSignIn: 38, gauntletCodes: 80, gauntletIdentity: 19, gauntletDom: 52, gauntletDom2: 50, gauntletFlows: 55, gauntletTraps: 115 },
}
}
71 changes: 70 additions & 1 deletion extension/e2e/gauntlet/traps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
// concealed inputs (the ACSAC 2024 concealment tricks), decoy fields that are
// no sign-in at all, a checkout whose fields all sit below the fold, code
// boxes that take a code only as a paste, a card form behind a strict mask,
// and a single-page app that signs in without a page load.
// a single-page app that signs in without a page load, a mailing address
// revealed by a radio button whose second line is "… Continued" and whose
// states load after the country, and two street boxes with one label.
// Every account, code and answer here is made up.

import type { Account, PageInfo } from "./site"
Expand All @@ -18,6 +20,8 @@ export const TRAP_PAGES: PageInfo[] = [
{ slug: "below-fold-checkout", group: "Traps", title: "Checkout below the fold", blurb: "Shipping address and card under a tall summary." },
{ slug: "paste-otp-boxes", group: "Traps", title: "Paste-only code boxes", blurb: "Six boxes that turn a written digit down and take the code only as a paste." },
{ slug: "masked-card", group: "Traps", title: "Strictly masked card", blurb: "Card number and expiry masks that take a character at a time." },
{ slug: "mailing-address-continued", group: "Traps", title: "Mailing address behind a radio button", blurb: "β€œAddress Continued”, 40 characters a line, states by number after the country." },
{ slug: "address-optional-line", group: "Traps", title: "Two street boxes, one label", blurb: "β€œStreet Address (optional)”, then a billing address in the same form." },
{ slug: "spa-shell-save", group: "Traps", title: "Single-page sign-in", blurb: "No page load: the form goes and an avatar menu shows. No Sign out link." },
]

Expand Down Expand Up @@ -261,7 +265,72 @@ document.getElementById("f").addEventListener("submit",async(e)=>{e.preventDefau
strictMaskScript,
)
},
// A payout form as claims and benefits sites draw one: the mailing
// address shows only once "Paper check" is chosen; its second street
// line is "… Continued" (no number, no autocomplete); both street lines
// take 40 characters at most; and the state list holds only
// <option value="0">Select</option> until the country is chosen, then
// loads options with the site's own numbers for values.
"mailing-address-continued": async (req, _u, _r, form) => {
const slug = "mailing-address-continued"
const STATES: Record<string, Array<[number, string]>> = {
CA: [[60, "ON - Ontario"], [61, "QC - Quebec"]],
US: [[5, "CA - California"], [32, "NY - New York"], [43, "TX - Texas"], [47, "WA - Washington"]],
}
if (req.method === "POST") {
const f = await form()
const long = ["street", "street_more"].filter((n) => (f[n] ?? "").length > 40)
const missing = ["first", "last", "street", "city", "zip"].filter((n) => !f[n]?.trim())
const state = (STATES[f.country] ?? []).find(([v]) => String(v) === f.state)
const error = f.method !== "check" ? "Choose Paper check." : long.length ? `${long.join(", ")}: too many characters` : missing.length || !state ? `Required: ${[...missing, ...(state ? [] : ["state"])].join(", ")}` : ""
if (error) return h("Payment method", `<h1>Payment method</h1><p class="error" id="error" role="alert">${esc(error)}</p><p class="muted"><a href="${url(slug)}">Back</a></p>`, slug)
const rows = Object.entries({ ...f, state: state![1] }).map(([n, v]) => `<tr><td class="muted">${esc(n)}</td><td>${esc(v)}</td></tr>`).join("")
return h("Saved", `<div class="result" id="result" data-ok="1"><h1>Saved</h1><table>${rows}</table></div>`, slug)
}
return h(
"Payment method",
`<h1>Payment method</h1><p class="lede">How would you like to be paid?</p><form method="post" action="${url(slug)}" novalidate>
<label><input type="radio" name="method" value="deposit" id="pay-deposit" checked> Direct deposit</label>
<label><input type="radio" name="method" value="check" id="pay-check"> Paper check</label>
<div id="mailing" style="display:none"><h2 style="font-size:15px;margin:16px 0 0">Where should we mail it?</h2>
<label for="first">*First Name</label><input id="first" name="first">
<label for="last">*Last Name</label><input id="last" name="last">
<label for="street">*Current Address</label><input id="street" name="street" maxlength="40">
<label for="street-more">Current Address Continued</label><input id="street-more" name="street_more" maxlength="40">
<label for="city">*City</label><input id="city" name="city">
<label for="country">*Country</label><select id="country" name="country"><option value="0">Select</option><option value="CA">Canada</option><option value="US">United States</option></select>
<label for="state">*State</label><select id="state" name="state"><option value="0">Select</option></select>
<label for="zip">*Zip Code</label><input id="zip" name="zip"></div>
<button type="submit" id="submit">Continue</button></form>`,
slug,
`const STATES=${JSON.stringify(STATES)};const c=document.getElementById("country"),s=document.getElementById("state"),m=document.getElementById("mailing")
for(const r of document.querySelectorAll("input[name=method]"))r.addEventListener("change",()=>{m.style.display=document.getElementById("pay-check").checked?"":"none"})
c.addEventListener("change",()=>{s.innerHTML='<option value="0">Select</option>';const chosen=c.value;setTimeout(()=>{if(c.value!==chosen)return;s.innerHTML='<option value="0">Select</option>'+(STATES[chosen]||[]).map(([v,n])=>'<option value="'+v+'">'+n+'</option>').join("")},150)})`,
)
},

// Two street boxes one after the other with the same label, the second
// only "(optional)", and a billing address after the shipping one in
// the same form under headings alone: the first two are one address's
// lines, and the billing address is still its own.
"address-optional-line": async (req) => {
const slug = "address-optional-line"
if (req.method === "POST") return k.savedProfile(req, slug)
const block = (p: string, second: boolean) =>
`<label for="${p}-street">Street Address</label><input id="${p}-street" name="${p}_street">
${second ? `<label for="${p}-street-b">Street Address (optional)</label><input id="${p}-street-b" name="${p}_street_b">` : ""}
<label for="${p}-city">City</label><input id="${p}-city" name="${p}_city">
<div class="row"><div><label for="${p}-state">State</label><select id="${p}-state" name="${p}_state"><option value="">State</option>${k.regions.map(([v, n]) => `<option value="${v}">${n}</option>`).join("")}</select></div>
<div><label for="${p}-zip">Postal Code</label><input id="${p}-zip" name="${p}_zip"></div></div>`
return h(
"Checkout",
`<h1>Checkout</h1><form method="post" action="${url(slug)}">
<h2 style="font-size:15px;margin:16px 0 0">Shipping address</h2>${block("ship", true)}
<h2 style="font-size:15px;margin:20px 0 0">Billing address</h2>${block("bill", false)}
<button type="submit" id="submit">Place order</button></form>`,
slug,
)
},
// Signs in without a page load: a wrong password shows an alert and
// clears the box; the right one swaps the form for an app shell whose
// only sign of the account is an avatar menu.
Expand Down
3 changes: 3 additions & 0 deletions extension/e2e/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,8 @@ interface LaunchOptions {
keyLogin?: boolean
/** "deny": the fake host turns down Touch ID for a card's number. */
touchId?: string
/** The fake host adds "Mailing", an identity with its whole address in its first line. */
oneLine?: boolean
/** http origins the browser treats as secure contexts, which WebAuthn needs. */
secure?: string[]
}
Expand Down Expand Up @@ -1358,6 +1360,7 @@ async function launch(options: LaunchOptions = {}): Promise<Run> {
DEADBOLT_FAKE_GOOGLE: options.google ? "1" : "",
DEADBOLT_FAKE_KEYLOGIN: options.keyLogin ? "1" : "",
DEADBOLT_FAKE_TOUCHID: options.touchId ?? "",
DEADBOLT_FAKE_ONE_LINE: options.oneLine ? "1" : "",
...options.realHost,
},
})
Expand Down
22 changes: 20 additions & 2 deletions extension/src/content/formfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ const approveCheck = (kind: FormKind, ours?: Element | null) => (el: FormControl
/** A select with nothing to choose yet: disabled, or only placeholder options (no value). */
const unloaded = (el: FormControl) => el instanceof HTMLSelectElement && (el.disabled || !Array.from(el.options).some((o) => o.value))

/**
* A state select beside a country that doesn't list the identity's region
* yet: a placeholder with a value of its own (`<option value="0">Select</option>`),
* or another country's regions, until the country chosen loads its own.
*/
const awaitsCountry = (f: FormField, roles: FormRole[], values: FormValues) =>
f.el instanceof HTMLSelectElement && f.role === "address-level1" && !!values.region && roles.includes("country") && valueFor(f.role, f.el, values) === undefined

/** Roles a mask often formats as they're typed, turning a whole value written at once down (see typeChars). */
const MASKED = new Set<FormRole>(["cc-number", "cc-exp", "tel", "tel-national"])

Expand Down Expand Up @@ -202,6 +210,8 @@ async function fillAll(fields: FormField[], given: FormValues, check: (el: FormC
const ok = (group: FormField[]) => (el: FormControl) => group.every(formFieldInPlace) && check(el)
const done = new Set<FormField>()
const later: FormField[] = []
/** Of `later`, the state selects that wait only on a country this fill chose. */
const onCountry = new Set<FormField>()
for (const f of ordered) {
if (done.has(f)) continue
if (f.role === "cc-number" && f.split) {
Expand All @@ -225,6 +235,12 @@ async function fillAll(fields: FormField[], given: FormValues, check: (el: FormC
later.push(f)
continue
}
// So does a state select with no option for the region: the country's change may load it.
if (awaitsCountry(f, roles, values)) {
later.push(f)
onCountry.add(f)
continue
}
// A combobox for a country or state is chosen in, not typed in (see combobox.ts).
if (isCombobox(f.el) && CHOICE_ROLES.has(f.role)) {
const choice = choiceFor(f.role, values)
Expand All @@ -251,8 +267,10 @@ async function fillAll(fields: FormField[], given: FormValues, check: (el: FormC
// option, through the full check.
const until = Date.now() + DEPENDENT_WAIT_MS
for (const f of filled.length ? later : []) {
let value: string | undefined
while (Date.now() < until && (unloaded(f.el) || (value = valueFor(f.role, f.el, values)) === undefined)) await sleep(100)
// No country chosen, no list to wait for: a state the select doesn't have is left alone at once.
if (onCountry.has(f) && !filled.includes("country")) continue
while ((unloaded(f.el) || valueFor(f.role, f.el, values) === undefined) && Date.now() < until) await sleep(100)
const value = unloaded(f.el) ? undefined : valueFor(f.role, f.el, values)
if (!value || !ok([f])(f.el)) continue
if (setFormValue(f.el, value, ok([f]))) {
filled.push(f.role)
Expand Down
Loading
Loading