Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40d27b6f92 | ||
|
|
f1a13a50a6 | ||
|
|
b4059af827 | ||
|
|
8c08b3d467 | ||
|
|
fd5921f62e | ||
|
|
83f3549d37 | ||
|
|
eb012b9eb3 | ||
|
|
adff1e0b9d | ||
|
|
8e52528f8b | ||
|
|
b8b13ef5cd | ||
|
|
ff05bd50f7 |
@@ -35,10 +35,10 @@ on: [push]
|
|||||||
jobs:
|
jobs:
|
||||||
e2e-chrome:
|
e2e-chrome:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
# Bounds the image build, a cold cache included, and both Chrome
|
# Bounds the image build, a cold cache included, and the three Chrome
|
||||||
# programs, so a hung browser frees the shared runner. README.md
|
# programs, so a hung browser frees the shared runner. README.md
|
||||||
# "In CI" has the measured times.
|
# "In CI" has the measured times.
|
||||||
timeout-minutes: 20
|
timeout-minutes: 40
|
||||||
steps:
|
steps:
|
||||||
# actions/checkout v4.2.2, 2026-02-22
|
# actions/checkout v4.2.2, 2026-02-22
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
||||||
|
|||||||
@@ -239,8 +239,12 @@ provide:
|
|||||||
`make check` stays non-mutating. Linting runs only in the container, because
|
`make check` stays non-mutating. Linting runs only in the container, because
|
||||||
an ESLint result that depends on whichever ESLint the host happens to have is
|
an ESLint result that depends on whichever ESLint the host happens to have is
|
||||||
not a result, so docker is required to lint.
|
not a result, so docker is required to lint.
|
||||||
- `script/fmt` — format all files (writes), on the host
|
- `script/fmt` — format all files (writes), on the host, with the `prettier`
|
||||||
- `script/fmt-check` — check formatting (read-only), on the host
|
that `script/bootstrap` installs in `node_modules/`; when that one is missing
|
||||||
|
it fails and says to run `script/bootstrap`, instead of using a `prettier`
|
||||||
|
from the `PATH`
|
||||||
|
- `script/fmt-check` — check formatting (read-only), on the host, with the same
|
||||||
|
`prettier` and the same refusal
|
||||||
- `script/check` — run `script/test`, `script/lint` and `script/fmt-check`
|
- `script/check` — run `script/test`, `script/lint` and `script/fmt-check`
|
||||||
- `script/check-censored` — assert the competitor name RULES.md bars appears
|
- `script/check-censored` — assert the competitor name RULES.md bars appears
|
||||||
nowhere in the working tree or under `dist/` outside its documented
|
nowhere in the working tree or under `dist/` outside its documented
|
||||||
@@ -422,11 +426,12 @@ captured at `eth_sendRawTransaction` rather than against anything the extension
|
|||||||
reported, rejecting each prompt is required to return a rejection to the page
|
reported, rejecting each prompt is required to return a rejection to the page
|
||||||
rather than hang or resolve, a network switch request is required to leave the
|
rather than hang or resolve, a network switch request is required to leave the
|
||||||
stored network unchanged and send no `chainChanged` until it is approved, a
|
stored network unchanged and send no `chainChanged` until it is approved, a
|
||||||
prompt raised while another approval window has focus is required to open a
|
network switch in Settings is required to send the page `chainChanged` with the
|
||||||
window of its own, and the password is required to be absent from every message
|
new chain id, a prompt raised while another approval window has focus is
|
||||||
the approval window sends to the background — with the message that would carry
|
required to open a window of its own, and the password is required to be absent
|
||||||
it required to be present, so that check cannot pass by observing nothing. That
|
from every message the approval window sends to the background — with the
|
||||||
last one is the standing floor under
|
message that would carry it required to be present, so that check cannot pass by
|
||||||
|
observing nothing. That last one is the standing floor under
|
||||||
[#157](https://git.eeqj.de/sneak/AutistMask/issues/157).
|
[#157](https://git.eeqj.de/sneak/AutistMask/issues/157).
|
||||||
|
|
||||||
The limits of that coverage and of the rest of the Chrome suite, none of them
|
The limits of that coverage and of the rest of the Chrome suite, none of them
|
||||||
@@ -522,6 +527,24 @@ one profile yields a single extension id, not two: Chrome does not load a second
|
|||||||
copy of an id it already has. The assertions are annotated as observations, so a
|
copy of an id it already has. The assertions are annotated as observations, so a
|
||||||
Chrome that ever changes this fails the run instead of passing it.
|
Chrome that ever changes this fails the run instead of passing it.
|
||||||
|
|
||||||
|
Last, `make test-e2e` runs `tests/e2e/slowApproval.js`, which leaves a
|
||||||
|
transaction approval and a signature approval open for seven minutes, then
|
||||||
|
approves both and requires the site to receive the hash of the transaction the
|
||||||
|
stub node received and a signature that recovers to the address. Before the
|
||||||
|
approval window kept the background worker running, Chrome stopped it about six
|
||||||
|
minutes in and neither request was ever answered
|
||||||
|
([#540](https://git.eeqj.de/sneak/AutistMask/issues/540)). It is its own program
|
||||||
|
and does not use Playwright: Playwright keeps DevTools attached to the
|
||||||
|
background worker, and Chrome never stops a worker DevTools is attached to, so
|
||||||
|
no wait in the suite above can show the worker stopping. It starts Chromium
|
||||||
|
itself, speaks the DevTools protocol over `--remote-debugging-pipe`, and
|
||||||
|
attaches to pages only. Before raising the approvals it requires the worker to
|
||||||
|
stop on its own with nothing pending, so a run in which something else keeps the
|
||||||
|
worker running fails. The site is connected and the RPC endpoint set through the
|
||||||
|
extension's own screens, against the Firefox suite's loopback dApp page and stub
|
||||||
|
node (`tests/e2e/firefox/dapp.js`). Unlike the suite above, it does not fail on
|
||||||
|
page errors.
|
||||||
|
|
||||||
### Firefox (`make test-e2e-firefox`)
|
### Firefox (`make test-e2e-firefox`)
|
||||||
|
|
||||||
`make test-e2e-firefox` builds `dist/firefox/` and drives the **real popup in a
|
`make test-e2e-firefox` builds `dist/firefox/` and drives the **real popup in a
|
||||||
@@ -702,11 +725,13 @@ installing Firefox, geckodriver and their system libraries. Both scripts now
|
|||||||
build their image with `--no-cache`, so every run pays the cold figure. Those
|
build their image with `--no-cache`, so every run pays the cold figure. Those
|
||||||
`e2e-chrome` runs predate the cases that wait in real time for a receipt to end
|
`e2e-chrome` runs predate the cases that wait in real time for a receipt to end
|
||||||
in error. `make test-e2e` took 3m51s locally with its image cached, so with the
|
in error. `make test-e2e` took 3m51s locally with its image cached, so with the
|
||||||
image rebuilt every run, an `e2e-chrome` run comes to about seven minutes.
|
image rebuilt every run, an `e2e-chrome` run comes to about seven minutes. The
|
||||||
|
approvals left open for seven minutes (`tests/e2e/slowApproval.js`) add about
|
||||||
|
eight more, so about fifteen.
|
||||||
|
|
||||||
Each e2e job has a `timeout-minutes` cap, so a hung build or browser ends the
|
Each e2e job has a `timeout-minutes` cap, so a hung build or browser ends the
|
||||||
job instead of holding the shared runner: `e2e-firefox` 15 minutes and
|
job instead of holding the shared runner: `e2e-firefox` 15 minutes and
|
||||||
`e2e-chrome` 20, each over two and a half times the job's slowest cold run. A
|
`e2e-chrome` 40, each over two and a half times the job's slowest cold run. A
|
||||||
job that reaches its cap has hung; read it as a hang, not as a slow run to
|
job that reaches its cap has hung; read it as a hang, not as a slow run to
|
||||||
retry. The `check` job has no cap: `.gitea/workflows/check.yml` is the canonical
|
retry. The `check` job has no cap: `.gitea/workflows/check.yml` is the canonical
|
||||||
copy from `sneak/prompts`, kept byte-identical.
|
copy from `sneak/prompts`, kept byte-identical.
|
||||||
@@ -801,6 +826,16 @@ on the next event. Two consequences shape every recurring job in the background:
|
|||||||
service worker at all — the one remaining user of it, `src/shared/ens.js`,
|
service worker at all — the one remaining user of it, `src/shared/ens.js`,
|
||||||
runs only in the popup and is marked as such.
|
runs only in the popup and is marked as such.
|
||||||
|
|
||||||
|
Pending approvals are the exception: an approval waiting for the user, and the
|
||||||
|
site's request waiting on it, live only in the worker's memory, and only the
|
||||||
|
worker that received the request can answer it. Chrome stopped the worker about
|
||||||
|
six minutes after a site's request even with the approval window still open, and
|
||||||
|
the user's answer then reached nobody. So while an approval window is open it
|
||||||
|
posts an empty message on its approval port every 20 seconds, and each message
|
||||||
|
is an event that keeps the worker running: an approval stays answerable however
|
||||||
|
long the user takes. A worker that stops for another reason, a crash say, still
|
||||||
|
loses the approvals open in it.
|
||||||
|
|
||||||
The job also carries a freshness guard, and a guard must never be timed to the
|
The job also carries a freshness guard, and a guard must never be timed to the
|
||||||
alarm period it gates. The guard is measured from the moment the last run
|
alarm period it gates. The guard is measured from the moment the last run
|
||||||
finished, which is one run-duration after the alarm that started it, so a guard
|
finished, which is one run-duration after the alarm that started it, so a guard
|
||||||
@@ -1789,7 +1824,8 @@ view would leave a wallet one click from deletion.
|
|||||||
network changes only here, or when the user approves a site's request on
|
network changes only here, or when the user approves a site's request on
|
||||||
**NetworkApproval**; either way, switching restores the RPC and Blockscout
|
**NetworkApproval**; either way, switching restores the RPC and Blockscout
|
||||||
endpoints last used on that network, or that network's defaults if it has
|
endpoints last used on that network, or that network's defaults if it has
|
||||||
none
|
none, and sends `chainChanged` with the new chain id to every open tab.
|
||||||
|
Choosing the network already active changes nothing and sends nothing
|
||||||
- Ethereum RPC: endpoint URL input + "Save" button (validated against
|
- Ethereum RPC: endpoint URL input + "Save" button (validated against
|
||||||
`eth_chainId` before being saved)
|
`eth_chainId` before being saved)
|
||||||
- Blockscout API: endpoint URL input + "Save" button (validated against
|
- Blockscout API: endpoint URL input + "Save" button (validated against
|
||||||
@@ -2158,6 +2194,13 @@ view would leave a wallet one click from deletion.
|
|||||||
- Typed data that states no primary type, or one other than the type it
|
- Typed data that states no primary type, or one other than the type it
|
||||||
would be signed as, or that cannot be read → shown with the error line
|
would be signed as, or that cannot be read → shown with the error line
|
||||||
saying so and "Sign" disabled; only "Reject" remains
|
saying so and "Sign" disabled; only "Reject" remains
|
||||||
|
- Typed data whose domain `chainId` names a chain other than the active
|
||||||
|
network's → shown with the error line naming both chain ids and "Sign"
|
||||||
|
disabled; only "Reject" remains. EIP-712 asks for this, because the
|
||||||
|
signature is valid on the chain the domain names. Typed data with no
|
||||||
|
`chainId` is not refused. The background refuses such a signature too,
|
||||||
|
against the network active when the signature reaches it, and answers the
|
||||||
|
site with the same sentence
|
||||||
- A `personal_sign` or `eth_sign` message that is not hex (`0x` or `0X` and
|
- A `personal_sign` or `eth_sign` message that is not hex (`0x` or `0X` and
|
||||||
an even number of hex digits, the form ethers' `getBytes` reads when
|
an even number of hex digits, the form ethers' `getBytes` reads when
|
||||||
signing) → shown as plain text, with the error line "This message is plain
|
signing) → shown as plain text, with the error line "This message is plain
|
||||||
@@ -2650,7 +2693,8 @@ plaintext list of anyone's domain names.
|
|||||||
When a dApp on a blocklisted domain requests a wallet connection, transaction
|
When a dApp on a blocklisted domain requests a wallet connection, transaction
|
||||||
approval, or signature, the approval popup displays a prominent red warning
|
approval, or signature, the approval popup displays a prominent red warning
|
||||||
banner alerting the user. The domain checker matches exact hostnames and all
|
banner alerting the user. The domain checker matches exact hostnames and all
|
||||||
parent domains (subdomain matching).
|
parent domains (subdomain matching), and checks a hostname written with a
|
||||||
|
trailing dot (`name.`) as `name`.
|
||||||
|
|
||||||
#### Transaction Decoding
|
#### Transaction Decoding
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
- `git pull` `next` and cut a branch from it — one branch per issue, named
|
- `git pull` `next` and cut a branch from it — one branch per issue, named
|
||||||
`issue-<N>-<slug>`. Never branch from `main`.
|
`issue-<N>-<slug>`. Never branch from `main`.
|
||||||
- Do the work as one commit whose title ends with ` (closes #N)`, with the
|
- Do the work as one commit whose title ends with ` (closes #N)`.
|
||||||
`TODO.md` update in that same commit.
|
- Add no entry to Completed Steps. What landed is recorded on the tracker and in
|
||||||
- Move Next Step to the top of Completed Steps; move the top item of Future
|
`git log`, where each commit title names the issue it closes.
|
||||||
Steps into Next Step.
|
|
||||||
- Run `make fmt`, then `make check`. A feature branch may be red; `next` and
|
- Run `make fmt`, then `make check`. A feature branch may be red; `next` and
|
||||||
`main` may not.
|
`main` may not.
|
||||||
- Rebase onto current `next` immediately before pushing — other branches land on
|
- Rebase onto current `next` immediately before pushing — other branches land on
|
||||||
@@ -44,6 +43,25 @@ then continue tagging as milestones land.
|
|||||||
|
|
||||||
# Completed Steps
|
# Completed Steps
|
||||||
|
|
||||||
|
- 2026-10-08: The browser suites no longer read a screen before the page has
|
||||||
|
shown it ([#502](https://git.eeqj.de/sneak/AutistMask/issues/502)). Their wait
|
||||||
|
for a screen used to pass as soon as the element laid out, which every view
|
||||||
|
does until the page's stylesheet has applied, so an approval test could read
|
||||||
|
the prompt's fields before the page's script had filled them. `visible()` in
|
||||||
|
`tests/e2e/harness.js` and `waitVisible()` in `tests/e2e/firefox/driver.js`
|
||||||
|
now also wait for the page to finish loading and for neither the element nor
|
||||||
|
anything around it to carry the `hidden` class that `showView()` puts on every
|
||||||
|
view but the current one. No caller changed.
|
||||||
|
|
||||||
|
- 2026-10-08: Switching the network in Settings now tells open pages
|
||||||
|
([#500](https://git.eeqj.de/sneak/AutistMask/issues/500)). Once the switch is
|
||||||
|
saved, Settings asks the background to send `chainChanged` with the new chain
|
||||||
|
id to every open tab, through the same function an approved site request uses.
|
||||||
|
Choosing the network already active changes nothing and sends nothing. Only
|
||||||
|
the extension's own pages can ask for this. `tests/chainSwitchGate.test.js`
|
||||||
|
drives the real Settings view against the background, and the Chrome suite
|
||||||
|
checks that the test page hears both switches.
|
||||||
|
|
||||||
- 2026-10-07: A site can no longer switch the wallet's network by itself
|
- 2026-10-07: A site can no longer switch the wallet's network by itself
|
||||||
([#408](https://git.eeqj.de/sneak/AutistMask/issues/408)). A connected site's
|
([#408](https://git.eeqj.de/sneak/AutistMask/issues/408)). A connected site's
|
||||||
`wallet_switchEthereumChain` request for the other supported network opens a
|
`wallet_switchEthereumChain` request for the other supported network opens a
|
||||||
|
|||||||
@@ -25,6 +25,13 @@ run_yarn() {
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
|
# Without the repo's own prettier, yarn runs whatever prettier is on
|
||||||
|
# the PATH, which may be a version that formats files differently.
|
||||||
|
if [ ! -x node_modules/.bin/prettier ]; then
|
||||||
|
echo "fmt: this repo's prettier is not installed in node_modules/," \
|
||||||
|
"so run script/bootstrap first." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
echo "Formatting..."
|
echo "Formatting..."
|
||||||
run_yarn run fmt
|
run_yarn run fmt
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,13 @@ run_yarn() {
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
|
# Without the repo's own prettier, yarn runs whatever prettier is on
|
||||||
|
# the PATH, which may be a version that formats files differently.
|
||||||
|
if [ ! -x node_modules/.bin/prettier ]; then
|
||||||
|
echo "fmt-check: this repo's prettier is not installed in" \
|
||||||
|
"node_modules/, so run script/bootstrap first." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
echo "Checking formatting..."
|
echo "Checking formatting..."
|
||||||
run_yarn run fmt-check
|
run_yarn run fmt-check
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,6 +97,18 @@ main() {
|
|||||||
-e HOME=/tmp \
|
-e HOME=/tmp \
|
||||||
"$(cat "$IIDFILE")" \
|
"$(cat "$IIDFILE")" \
|
||||||
node tests/e2e/storagePartition.js
|
node tests/e2e/storagePartition.js
|
||||||
|
|
||||||
|
# Approvals left open for seven minutes, past the point where Chrome
|
||||||
|
# stopped the background worker before the approval window kept it
|
||||||
|
# running. Its own program, without Playwright: Playwright keeps DevTools
|
||||||
|
# attached to the worker, and Chrome never stops a worker DevTools is
|
||||||
|
# attached to. It reaches nothing but its own loopback server.
|
||||||
|
echo "Running the approvals left open for seven minutes..."
|
||||||
|
docker run --rm \
|
||||||
|
--ipc=host \
|
||||||
|
-e HOME=/tmp \
|
||||||
|
"$(cat "$IIDFILE")" \
|
||||||
|
node tests/e2e/slowApproval.js
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
+34
-4
@@ -22,6 +22,7 @@ const { debugFetch, log } = require("../shared/log");
|
|||||||
const {
|
const {
|
||||||
verifySignedTx,
|
verifySignedTx,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
|
typedDataChainRefusal,
|
||||||
failureIsRetryable,
|
failureIsRetryable,
|
||||||
describeTxFailure,
|
describeTxFailure,
|
||||||
sameAddress,
|
sameAddress,
|
||||||
@@ -632,8 +633,9 @@ function isExtensionSender(sender) {
|
|||||||
// had refused.
|
// had refused.
|
||||||
//
|
//
|
||||||
// TX and sign approvals do not decide here. They stay pending across a
|
// TX and sign approvals do not decide here. They stay pending across a
|
||||||
// disconnect — the user can reopen the toolbar popup — and are rejected by the
|
// disconnect. When their window closes, the windows.onRemoved listener below
|
||||||
// windows.onRemoved listener below.
|
// rejects them, unless an approved attempt is still running, in which case
|
||||||
|
// that attempt answers the page.
|
||||||
runtime.onConnect.addListener((port) => {
|
runtime.onConnect.addListener((port) => {
|
||||||
if (port.name.startsWith("approval:")) {
|
if (port.name.startsWith("approval:")) {
|
||||||
const id = port.name.split(":")[1];
|
const id = port.name.split(":")[1];
|
||||||
@@ -647,6 +649,9 @@ runtime.onConnect.addListener((port) => {
|
|||||||
pendingApprovals[id].portConnected = true;
|
pendingApprovals[id].portConnected = true;
|
||||||
}
|
}
|
||||||
port.onMessage.addListener((msg) => {
|
port.onMessage.addListener((msg) => {
|
||||||
|
// The window also posts an empty message every 20 seconds while
|
||||||
|
// it is open, only so that Chrome keeps this worker, and the
|
||||||
|
// approval in it, running (src/popup/views/approval.js, show()).
|
||||||
if (!msg || msg.type !== "AUTISTMASK_APPROVAL_DECISION") return;
|
if (!msg || msg.type !== "AUTISTMASK_APPROVAL_DECISION") return;
|
||||||
if (!isExtensionSender(port.sender)) return;
|
if (!isExtensionSender(port.sender)) return;
|
||||||
const approval = pendingApprovals[id];
|
const approval = pendingApprovals[id];
|
||||||
@@ -661,7 +666,9 @@ runtime.onConnect.addListener((port) => {
|
|||||||
const approval = pendingApprovals[id];
|
const approval = pendingApprovals[id];
|
||||||
if (approval) {
|
if (approval) {
|
||||||
if (approval.type === "tx" || approval.type === "sign") {
|
if (approval.type === "tx" || approval.type === "sign") {
|
||||||
// Keep pending — user can reopen the toolbar popup
|
// When its window closes, windows.onRemoved rejects it,
|
||||||
|
// unless an approved attempt is still running, in which
|
||||||
|
// case that attempt answers the page.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
settleApproval(id, { approved: false, remember: false });
|
settleApproval(id, { approved: false, remember: false });
|
||||||
@@ -1471,6 +1478,7 @@ runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
|||||||
"AUTISTMASK_ADDRESSES_REMOVED",
|
"AUTISTMASK_ADDRESSES_REMOVED",
|
||||||
"AUTISTMASK_GET_CONNECTED_SITES",
|
"AUTISTMASK_GET_CONNECTED_SITES",
|
||||||
"AUTISTMASK_REMOVE_SITE",
|
"AUTISTMASK_REMOVE_SITE",
|
||||||
|
"AUTISTMASK_NETWORK_CHANGED",
|
||||||
];
|
];
|
||||||
if (POPUP_ONLY_TYPES.includes(msg.type) && !isExtensionSender(sender)) {
|
if (POPUP_ONLY_TYPES.includes(msg.type) && !isExtensionSender(sender)) {
|
||||||
sendResponse({ error: "Unauthorized sender" });
|
sendResponse({ error: "Unauthorized sender" });
|
||||||
@@ -1763,7 +1771,8 @@ runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
|||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const activeAddress = await getActiveAddress();
|
const s = await getState();
|
||||||
|
const activeAddress = activeAddressOf(s);
|
||||||
// Same as the transaction path: the address the approval named
|
// Same as the transaction path: the address the approval named
|
||||||
// is the one that must have signed, and a switch since then is
|
// is the one that must have signed, and a switch since then is
|
||||||
// a refusal rather than a signature from another account.
|
// a refusal rather than a signature from another account.
|
||||||
@@ -1782,6 +1791,20 @@ runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
|||||||
signature,
|
signature,
|
||||||
approval.approvedFrom,
|
approval.approvedFrom,
|
||||||
);
|
);
|
||||||
|
// The sign screen refuses typed data whose domain names
|
||||||
|
// another chain. A signature for it that arrives anyway is
|
||||||
|
// refused here, against the network active now.
|
||||||
|
const sp = approval.signParams;
|
||||||
|
if (
|
||||||
|
sp.method === "eth_signTypedData_v4" ||
|
||||||
|
sp.method === "eth_signTypedData"
|
||||||
|
) {
|
||||||
|
const refusal = typedDataChainRefusal(
|
||||||
|
JSON.parse(sp.typedData).domain,
|
||||||
|
networkById(s.networkId),
|
||||||
|
);
|
||||||
|
if (refusal) throw new ApprovalMismatchError(refusal);
|
||||||
|
}
|
||||||
settleApproval(msg.id, { signature }, { holdsClaim: true });
|
settleApproval(msg.id, { signature }, { holdsClaim: true });
|
||||||
sendResponse({ signature });
|
sendResponse({ signature });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -1854,6 +1877,13 @@ runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
|||||||
broadcastSiteRemoved(msg.origin);
|
broadcastSiteRemoved(msg.origin);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Settings switched the network and has saved it. Open tabs are told the
|
||||||
|
// new chain id the same way as after a site's approved switch request.
|
||||||
|
if (msg.type === "AUTISTMASK_NETWORK_CHANGED") {
|
||||||
|
broadcastChainChanged(msg.chainId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = { PROXY_METHODS };
|
module.exports = { PROXY_METHODS };
|
||||||
|
|||||||
+12
-8
@@ -7,9 +7,10 @@
|
|||||||
<link rel="stylesheet" href="styles.css" />
|
<link rel="stylesheet" href="styles.css" />
|
||||||
</head>
|
</head>
|
||||||
<!-- Chrome gives extension pages a stylesheet of its own that sets the
|
<!-- Chrome gives extension pages a stylesheet of its own that sets the
|
||||||
font on body, and a Tailwind class beats it only when marked
|
font and its size on body, and a Tailwind class beats it only when
|
||||||
important: hence font-mono! rather than font-mono. -->
|
marked important: hence font-mono! and text-sm! rather than
|
||||||
<body class="bg-bg text-fg font-mono! text-sm">
|
font-mono and text-sm. -->
|
||||||
|
<body class="bg-bg text-fg font-mono! text-sm!">
|
||||||
<div id="app" class="p-2 pr-5 overflow-x-hidden">
|
<div id="app" class="p-2 pr-5 overflow-x-hidden">
|
||||||
<!-- ============ GLOBAL TITLE BAR ============ -->
|
<!-- ============ GLOBAL TITLE BAR ============ -->
|
||||||
<div
|
<div
|
||||||
@@ -87,11 +88,14 @@
|
|||||||
|
|
||||||
<!-- Mnemonic form section -->
|
<!-- Mnemonic form section -->
|
||||||
<div id="add-wallet-section-mnemonic">
|
<div id="add-wallet-section-mnemonic">
|
||||||
<p class="mb-2">
|
<!-- The die button shares the instruction's row: on a row
|
||||||
Enter your 12 or 24 word recovery phrase below, or click
|
of its own it pushes Import below the fold at
|
||||||
the button to roll the die for a new one.
|
360x600. -->
|
||||||
</p>
|
<div class="mb-2 flex justify-between items-start gap-2">
|
||||||
<div class="mb-1 flex justify-end">
|
<p>
|
||||||
|
Enter your 12 or 24 word recovery phrase below, or
|
||||||
|
click the button to roll the die for a new one.
|
||||||
|
</p>
|
||||||
<button
|
<button
|
||||||
id="btn-generate-phrase"
|
id="btn-generate-phrase"
|
||||||
class="border border-border px-2 py-1 hover:bg-fg hover:text-bg cursor-pointer text-xs"
|
class="border border-border px-2 py-1 hover:bg-fg hover:text-bg cursor-pointer text-xs"
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const {
|
|||||||
formatFee,
|
formatFee,
|
||||||
tokenLabel,
|
tokenLabel,
|
||||||
} = require("./helpers");
|
} = require("./helpers");
|
||||||
const { state, saveState } = require("../../shared/state");
|
const { state, saveState, currentNetwork } = require("../../shared/state");
|
||||||
const {
|
const {
|
||||||
networkById,
|
networkById,
|
||||||
networkByChainId,
|
networkByChainId,
|
||||||
@@ -46,7 +46,10 @@ const {
|
|||||||
const { decryptWithPassword } = require("../../shared/vault");
|
const { decryptWithPassword } = require("../../shared/vault");
|
||||||
const { getSignerForAddress } = require("../../shared/wallet");
|
const { getSignerForAddress } = require("../../shared/wallet");
|
||||||
const { walletDefect } = require("../../shared/walletDefects");
|
const { walletDefect } = require("../../shared/walletDefects");
|
||||||
const { describeSigningFailure } = require("../../shared/approvalVerify");
|
const {
|
||||||
|
describeSigningFailure,
|
||||||
|
typedDataChainRefusal,
|
||||||
|
} = require("../../shared/approvalVerify");
|
||||||
const txStatus = require("./txStatus");
|
const txStatus = require("./txStatus");
|
||||||
const uniswap = require("../../shared/uniswap");
|
const uniswap = require("../../shared/uniswap");
|
||||||
const { notify, runtimeApi, sendMessage } = require("../../shared/browserApi");
|
const { notify, runtimeApi, sendMessage } = require("../../shared/browserApi");
|
||||||
@@ -443,7 +446,8 @@ function signedPrimaryType(types) {
|
|||||||
// Why a signature request cannot be signed, as a sentence for the error line,
|
// Why a signature request cannot be signed, as a sentence for the error line,
|
||||||
// or null when it can. Only typed data is refused: the `primaryType` the page
|
// or null when it can. Only typed data is refused: the `primaryType` the page
|
||||||
// states has to be the type ethers will sign, or this screen would name one
|
// states has to be the type ethers will sign, or this screen would name one
|
||||||
// message while another is signed.
|
// message while another is signed. Its domain may name no chain but the active
|
||||||
|
// network's.
|
||||||
function typedDataRefusal(sp) {
|
function typedDataRefusal(sp) {
|
||||||
if (sp.method === "personal_sign" || sp.method === "eth_sign") return null;
|
if (sp.method === "personal_sign" || sp.method === "eth_sign") return null;
|
||||||
let data;
|
let data;
|
||||||
@@ -466,7 +470,7 @@ function typedDataRefusal(sp) {
|
|||||||
", so it cannot be signed."
|
", so it cannot be signed."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return null;
|
return typedDataChainRefusal(data.domain, currentNetwork());
|
||||||
}
|
}
|
||||||
|
|
||||||
// The largest amount a Permit2 allowance can hold, a uint160. Permit2 treats
|
// The largest amount a Permit2 allowance can hold, a uint160. Permit2 treats
|
||||||
@@ -780,6 +784,22 @@ async function show(id) {
|
|||||||
approvalId = id;
|
approvalId = id;
|
||||||
approvalPort = runtimeApi().connect({ name: "approval:" + id });
|
approvalPort = runtimeApi().connect({ name: "approval:" + id });
|
||||||
|
|
||||||
|
// The approval this window answers, and the site's request waiting on it,
|
||||||
|
// exist only in the background worker's memory. Chrome stops that worker
|
||||||
|
// about six minutes after the site's request even while the user is still
|
||||||
|
// deciding, and the approval is lost with it. A message on this port is an
|
||||||
|
// event, and an event keeps the worker running, so one is sent every 20
|
||||||
|
// seconds for as long as this window is open. The background ignores it.
|
||||||
|
const port = approvalPort;
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
try {
|
||||||
|
port.postMessage({});
|
||||||
|
} catch {
|
||||||
|
// The worker is gone anyway, and the port with it.
|
||||||
|
clearInterval(timer);
|
||||||
|
}
|
||||||
|
}, 20000);
|
||||||
|
|
||||||
let details = null;
|
let details = null;
|
||||||
try {
|
try {
|
||||||
details = await sendMessage({ type: "AUTISTMASK_GET_APPROVAL", id });
|
details = await sendMessage({ type: "AUTISTMASK_GET_APPROVAL", id });
|
||||||
|
|||||||
@@ -316,7 +316,11 @@ function init(ctx) {
|
|||||||
const networkSelect = $("settings-network");
|
const networkSelect = $("settings-network");
|
||||||
networkSelect.addEventListener("change", async () => {
|
networkSelect.addEventListener("change", async () => {
|
||||||
const newId = networkSelect.value;
|
const newId = networkSelect.value;
|
||||||
|
if (newId === state.networkId) return;
|
||||||
const net = await onChainSwitch(newId);
|
const net = await onChainSwitch(newId);
|
||||||
|
// Open pages are told by the background, as after a site's approved
|
||||||
|
// switch request.
|
||||||
|
notify({ type: "AUTISTMASK_NETWORK_CHANGED", chainId: net.chainId });
|
||||||
$("settings-rpc").value = state.rpcUrl;
|
$("settings-rpc").value = state.rpcUrl;
|
||||||
$("settings-blockscout").value = state.blockscoutUrl;
|
$("settings-blockscout").value = state.blockscoutUrl;
|
||||||
showFlash("Switched to " + net.name + ".");
|
showFlash("Switched to " + net.name + ".");
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ const {
|
|||||||
accessListify,
|
accessListify,
|
||||||
formatEther,
|
formatEther,
|
||||||
getAddress,
|
getAddress,
|
||||||
|
getBigInt,
|
||||||
getBytes,
|
getBytes,
|
||||||
toQuantity,
|
toQuantity,
|
||||||
verifyMessage,
|
verifyMessage,
|
||||||
@@ -635,6 +636,33 @@ function verifySignature(signParams, signature, expectedFrom) {
|
|||||||
return recovered;
|
return recovered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Why typed data cannot be signed while `network` is the active network, as a
|
||||||
|
// sentence, or null when it can. EIP-712 has a wallet refuse typed data whose
|
||||||
|
// domain names another chain, because the signature is valid on that chain.
|
||||||
|
// ethers signs no chain id when the domain's is null or absent, and reads any
|
||||||
|
// other with getBigInt(), so 1, "1" and "0x1" are the same chain here too.
|
||||||
|
function typedDataChainRefusal(domain, network) {
|
||||||
|
const chainId = domain?.chainId;
|
||||||
|
if (chainId === undefined || chainId === null) return null;
|
||||||
|
let named;
|
||||||
|
try {
|
||||||
|
named = getBigInt(chainId);
|
||||||
|
} catch {
|
||||||
|
return "This typed data cannot be read, so it cannot be signed.";
|
||||||
|
}
|
||||||
|
const active = getBigInt(network.chainId);
|
||||||
|
if (named === active) return null;
|
||||||
|
return (
|
||||||
|
"This typed data is for chain id " +
|
||||||
|
named +
|
||||||
|
", but the active network is " +
|
||||||
|
network.name +
|
||||||
|
" (chain id " +
|
||||||
|
active +
|
||||||
|
"), so it cannot be signed."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// The stage a transaction approval failed at. Which stage it is decides
|
// The stage a transaction approval failed at. Which stage it is decides
|
||||||
// whether the approval survives the failure.
|
// whether the approval survives the failure.
|
||||||
const TX_STAGE_SIGN = "sign";
|
const TX_STAGE_SIGN = "sign";
|
||||||
@@ -796,6 +824,7 @@ function describeSigningFailure(response, fallbackMessage) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
verifySignedTx,
|
verifySignedTx,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
|
typedDataChainRefusal,
|
||||||
assertNoForbiddenFields,
|
assertNoForbiddenFields,
|
||||||
assertNothingUnchecked,
|
assertNothingUnchecked,
|
||||||
assertCanonicalBytes,
|
assertCanonicalBytes,
|
||||||
|
|||||||
@@ -110,11 +110,14 @@ function hashListed(hash) {
|
|||||||
* Generate hostname variants for subdomain matching.
|
* Generate hostname variants for subdomain matching.
|
||||||
* "sub.evil.com" yields ["sub.evil.com", "evil.com"].
|
* "sub.evil.com" yields ["sub.evil.com", "evil.com"].
|
||||||
*
|
*
|
||||||
|
* A trailing dot is dropped: "evil.com." is the fully qualified spelling of
|
||||||
|
* "evil.com", and the browser loads the same site from either.
|
||||||
|
*
|
||||||
* @param {string} hostname
|
* @param {string} hostname
|
||||||
* @returns {string[]}
|
* @returns {string[]}
|
||||||
*/
|
*/
|
||||||
function hostnameVariants(hostname) {
|
function hostnameVariants(hostname) {
|
||||||
const h = hostname.toLowerCase();
|
const h = hostname.toLowerCase().replace(/\.$/, "");
|
||||||
const variants = [h];
|
const variants = [h];
|
||||||
const parts = h.split(".");
|
const parts = h.split(".");
|
||||||
// Parent domains: a.b.c.d -> b.c.d, c.d
|
// Parent domains: a.b.c.d -> b.c.d, c.d
|
||||||
|
|||||||
@@ -36,11 +36,13 @@ const DEFECTS = {
|
|||||||
"derivation path beneath that key instead of from a master " +
|
"derivation path beneath that key instead of from a master " +
|
||||||
"key, so the addresses listed here are not the ones that key " +
|
"key, so the addresses listed here are not the ones that key " +
|
||||||
"produces under the standard path.",
|
"produces under the standard path.",
|
||||||
"Signing and sending are disabled for this wallet. The addresses " +
|
"Signing, sending and private key export are disabled for this " +
|
||||||
"do descend from the extended private key you imported, so " +
|
"wallet. Anything these addresses hold can be reached outside " +
|
||||||
"anything they hold is still reachable by software that " +
|
"this wallet with the extended private key you imported, if " +
|
||||||
"repeats the same non-standard derivation. Check them in a " +
|
"you kept a copy of it, or with the master extended private " +
|
||||||
"block explorer before deciding what to do.",
|
"key or recovery phrase it came from, in software that " +
|
||||||
|
"repeats the same non-standard derivation. Check the " +
|
||||||
|
"addresses in a block explorer before deciding what to do.",
|
||||||
"To see the addresses this key produces under the standard path, " +
|
"To see the addresses this key produces under the standard path, " +
|
||||||
"import the master extended private key, or the recovery " +
|
"import the master extended private key, or the recovery " +
|
||||||
"phrase it came from, as a new wallet. Nothing here has been " +
|
"phrase it came from, as a new wallet. Nothing here has been " +
|
||||||
|
|||||||
@@ -397,7 +397,13 @@ function loadBackground(options) {
|
|||||||
rpcResult = r;
|
rpcResult = r;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return { result: () => rpcResult };
|
return {
|
||||||
|
id: () =>
|
||||||
|
new URL(created[created.length - 1].url).searchParams.get(
|
||||||
|
"approval",
|
||||||
|
),
|
||||||
|
result: () => rpcResult,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// A dApp asking to connect. The origin defaults to one the persisted
|
// A dApp asking to connect. The origin defaults to one the persisted
|
||||||
@@ -1484,6 +1490,55 @@ describe("what the approval is verified against", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Typed data whose domain names another chain is refused on the sign
|
||||||
|
// screen; a signature for it that reaches the background anyway is not
|
||||||
|
// handed to the page (https://git.eeqj.de/sneak/AutistMask/issues/519).
|
||||||
|
// TYPED_DATA names mainnet.
|
||||||
|
async function answerTypedData(bg, pending) {
|
||||||
|
const { domain, types, message } = JSON.parse(TYPED_DATA);
|
||||||
|
delete types.EIP712Domain;
|
||||||
|
const signature = await signer.signTypedData(domain, types, message);
|
||||||
|
const answer = bg.send(
|
||||||
|
{
|
||||||
|
type: "AUTISTMASK_SIGN_RESPONSE",
|
||||||
|
id: pending.id(),
|
||||||
|
approved: true,
|
||||||
|
signature,
|
||||||
|
},
|
||||||
|
{ url: bg.fromPopup.url },
|
||||||
|
);
|
||||||
|
await settle();
|
||||||
|
return { answer, signature };
|
||||||
|
}
|
||||||
|
|
||||||
|
test("typed data for the active chain is handed back signed", async () => {
|
||||||
|
const bg = loadBackground();
|
||||||
|
const pending = bg.requestTypedData();
|
||||||
|
await settle();
|
||||||
|
|
||||||
|
const { answer, signature } = await answerTypedData(bg, pending);
|
||||||
|
|
||||||
|
expect(answer.sendResponse).toHaveBeenCalledWith({ signature });
|
||||||
|
expect(pending.result()).toEqual({ result: signature });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("typed data for another chain is refused, not handed back", async () => {
|
||||||
|
const bg = loadBackground();
|
||||||
|
bg.setNetwork(SEPOLIA);
|
||||||
|
const pending = bg.requestTypedData();
|
||||||
|
await settle();
|
||||||
|
|
||||||
|
const { answer } = await answerTypedData(bg, pending);
|
||||||
|
|
||||||
|
const refusal =
|
||||||
|
"This typed data is for chain id 1, but the active network is Sepolia Testnet (chain id 11155111), so it cannot be signed.";
|
||||||
|
expect(answer.sendResponse).toHaveBeenCalledWith({
|
||||||
|
error: refusal,
|
||||||
|
retryable: false,
|
||||||
|
});
|
||||||
|
expect(pending.result()).toEqual({ error: { message: refusal } });
|
||||||
|
});
|
||||||
|
|
||||||
test("a sign request from another address raises no approval at all", async () => {
|
test("a sign request from another address raises no approval at all", async () => {
|
||||||
const bg = loadBackground();
|
const bg = loadBackground();
|
||||||
const pending = bg.requestSign(other.address);
|
const pending = bg.requestSign(other.address);
|
||||||
|
|||||||
@@ -16,7 +16,9 @@
|
|||||||
//
|
//
|
||||||
// The endpoint half of #308 lives in tests/networkEndpoints.test.js, which
|
// The endpoint half of #308 lives in tests/networkEndpoints.test.js, which
|
||||||
// covers the popup's chain switch; this file covers the background's, which
|
// covers the popup's chain switch; this file covers the background's, which
|
||||||
// goes through storage rather than the shared state singleton.
|
// goes through storage rather than the shared state singleton. The last block
|
||||||
|
// covers what the background tells open tabs when the user switches the
|
||||||
|
// network in Settings.
|
||||||
|
|
||||||
const { networkById } = require("../src/shared/networks");
|
const { networkById } = require("../src/shared/networks");
|
||||||
const { makeStorageStub } = require("./support/storageStub");
|
const { makeStorageStub } = require("./support/storageStub");
|
||||||
@@ -225,6 +227,14 @@ function loadBackground() {
|
|||||||
answerPrompt,
|
answerPrompt,
|
||||||
closePrompt,
|
closePrompt,
|
||||||
opened,
|
opened,
|
||||||
|
// A message to the background from `sender`, and its answer.
|
||||||
|
send: (msg, sender) => {
|
||||||
|
let reply = null;
|
||||||
|
messageListener(msg, sender, (r) => {
|
||||||
|
reply = r;
|
||||||
|
});
|
||||||
|
return reply;
|
||||||
|
},
|
||||||
walletState: () => storage.read("autistmask"),
|
walletState: () => storage.read("autistmask"),
|
||||||
chainChangedEvents: () =>
|
chainChangedEvents: () =>
|
||||||
toTabs.filter((m) => m.eventName === "chainChanged"),
|
toTabs.filter((m) => m.eventName === "chainChanged"),
|
||||||
@@ -390,3 +400,109 @@ describe("only the user switches the network", () => {
|
|||||||
expect(bg.walletState().rpcUrl).toBe(CUSTOM_RPC);
|
expect(bg.walletState().rpcUrl).toBe(CUSTOM_RPC);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Switching the network in Settings tells open pages, as an approved site
|
||||||
|
// request does (https://git.eeqj.de/sneak/AutistMask/issues/500). These drive
|
||||||
|
// the real Settings view over the background's storage, with what it sends
|
||||||
|
// delivered to the background from the extension's own page.
|
||||||
|
describe("switching the network in Settings tells every open tab", () => {
|
||||||
|
const POPUP = { url: EXT_URL + "src/popup/index.html" };
|
||||||
|
|
||||||
|
// A stand-in for one DOM node: enough of an element for init() to set
|
||||||
|
// properties on it and hang listeners off it.
|
||||||
|
function fakeElement() {
|
||||||
|
return {
|
||||||
|
value: "",
|
||||||
|
checked: false,
|
||||||
|
textContent: "",
|
||||||
|
style: {},
|
||||||
|
dataset: {},
|
||||||
|
classList: { add() {}, remove() {} },
|
||||||
|
listeners: {},
|
||||||
|
addEventListener(event, handler) {
|
||||||
|
this.listeners[event] = handler;
|
||||||
|
},
|
||||||
|
querySelectorAll: () => [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Settings, opened the way the popup opens it. Returns its network
|
||||||
|
// selector.
|
||||||
|
async function openSettings(bg) {
|
||||||
|
const elements = {};
|
||||||
|
const element = (id) => (elements[id] ||= fakeElement());
|
||||||
|
jest.doMock("../src/popup/views/helpers", () => ({
|
||||||
|
$: element,
|
||||||
|
showView: () => {},
|
||||||
|
updateDebugBanner: () => {},
|
||||||
|
showFlash: () => {},
|
||||||
|
escapeHtml: (s) => s,
|
||||||
|
flashCopyFeedback: () => {},
|
||||||
|
goBack: () => {},
|
||||||
|
pushCurrentView: () => {},
|
||||||
|
onViewLeave: () => {},
|
||||||
|
VIEWS: [],
|
||||||
|
}));
|
||||||
|
global.chrome.runtime.sendMessage = (msg) => {
|
||||||
|
bg.send(msg, POPUP);
|
||||||
|
};
|
||||||
|
await require("../src/shared/state").loadState();
|
||||||
|
require("../src/popup/views/settings").init({
|
||||||
|
pageClosed: new AbortController().signal,
|
||||||
|
});
|
||||||
|
const select = element("settings-network");
|
||||||
|
select.value = "mainnet";
|
||||||
|
return select;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The user picks `networkId` in the selector.
|
||||||
|
async function choose(select, networkId) {
|
||||||
|
select.value = networkId;
|
||||||
|
await select.listeners.change();
|
||||||
|
await settle();
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.dontMock("../src/popup/views/helpers");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("switching to the other network sends chainChanged once, with its chain id", async () => {
|
||||||
|
const bg = loadBackground();
|
||||||
|
const select = await openSettings(bg);
|
||||||
|
|
||||||
|
await choose(select, "sepolia");
|
||||||
|
|
||||||
|
expect(bg.walletState().networkId).toBe("sepolia");
|
||||||
|
expect(bg.chainChangedEvents()).toEqual([
|
||||||
|
{
|
||||||
|
type: "AUTISTMASK_EVENT",
|
||||||
|
eventName: "chainChanged",
|
||||||
|
data: SEPOLIA.chainId,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("choosing the network already active changes nothing and sends nothing", async () => {
|
||||||
|
const bg = loadBackground();
|
||||||
|
const select = await openSettings(bg);
|
||||||
|
const before = bg.walletState();
|
||||||
|
|
||||||
|
await choose(select, "mainnet");
|
||||||
|
|
||||||
|
expect(bg.walletState()).toEqual(before);
|
||||||
|
expect(bg.chainChangedEvents()).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a page cannot make the background send chainChanged", async () => {
|
||||||
|
const bg = loadBackground();
|
||||||
|
|
||||||
|
const reply = bg.send(
|
||||||
|
{ type: "AUTISTMASK_NETWORK_CHANGED", chainId: SEPOLIA.chainId },
|
||||||
|
{ url: CONNECTED_ORIGIN + "/" },
|
||||||
|
);
|
||||||
|
await settle();
|
||||||
|
|
||||||
|
expect(reply).toEqual({ error: "Unauthorized sender" });
|
||||||
|
expect(bg.chainChangedEvents()).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -279,12 +279,18 @@ class Driver {
|
|||||||
|
|
||||||
// Shown means shown: in the popup a view is switched by toggling a
|
// Shown means shown: in the popup a view is switched by toggling a
|
||||||
// "hidden" class, and an element that is present but collapsed is not
|
// "hidden" class, and an element that is present but collapsed is not
|
||||||
// the thing a test means by visible.
|
// the thing a test means by visible. Until the page's stylesheet has
|
||||||
|
// applied that class hides nothing and every view lays out, so the page
|
||||||
|
// must also have finished loading, which it does only after its
|
||||||
|
// stylesheet, and neither the element nor anything enclosing it may
|
||||||
|
// carry the class (https://git.eeqj.de/sneak/AutistMask/issues/502).
|
||||||
async waitVisible(selector, timeout = DEFAULT_WAIT_MS) {
|
async waitVisible(selector, timeout = DEFAULT_WAIT_MS) {
|
||||||
return this.waitFor(
|
return this.waitFor(
|
||||||
"selector " + selector + " to be visible",
|
"selector " + selector + " to be visible",
|
||||||
`const el = document.querySelector(arguments[0]);
|
`const el = document.querySelector(arguments[0]);
|
||||||
if (!el) return false;
|
if (document.readyState !== "complete" || !el) return false;
|
||||||
|
if (el.closest(".hidden")) return false;
|
||||||
|
if (getComputedStyle(el).visibility !== "visible") return false;
|
||||||
const r = el.getBoundingClientRect();
|
const r = el.getBoundingClientRect();
|
||||||
return r.width > 0 && r.height > 0;`,
|
return r.width > 0 && r.height > 0;`,
|
||||||
[selector],
|
[selector],
|
||||||
|
|||||||
@@ -128,6 +128,18 @@ step("the popup is drawn in the monospace font it declares", async (env) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// The same check as the Chrome suite's (#456), so both browsers are held to
|
||||||
|
// the same size.
|
||||||
|
step("the popup's text is drawn at the 14px text-sm declares", async (env) => {
|
||||||
|
const size = await env.driver.execute(
|
||||||
|
"return getComputedStyle(document.body).fontSize;",
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
size === "14px",
|
||||||
|
"the popup's text is drawn at " + size + ", not at the 14px of text-sm",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// The recovery screen (#361): the Chrome suite's four cases, run before any
|
// The recovery screen (#361): the Chrome suite's four cases, run before any
|
||||||
// wallet exists for the same reason. With no wallet nothing saves on a timer,
|
// wallet exists for the same reason. With no wallet nothing saves on a timer,
|
||||||
// so no save can write a good record over the unreadable one. The last of them
|
// so no save can write a good record over the unreadable one. The last of them
|
||||||
|
|||||||
+26
-1
@@ -333,8 +333,33 @@ async function launch(routeOpts) {
|
|||||||
|
|
||||||
const PASSWORD = "e2e-harness-password";
|
const PASSWORD = "e2e-harness-password";
|
||||||
|
|
||||||
|
// Waits until the page shows `selector`, not only until it lays out. Until the
|
||||||
|
// page's stylesheet has applied, the `hidden` class that showView() keeps on
|
||||||
|
// every view but the current one hides nothing and every view lays out, so a
|
||||||
|
// test could read a screen before the page's script had filled it
|
||||||
|
// (https://git.eeqj.de/sneak/AutistMask/issues/502). So the page must also
|
||||||
|
// have finished loading, which it does only after its stylesheet, and neither
|
||||||
|
// the element nor anything enclosing it may carry `hidden`. Polled on a timer:
|
||||||
|
// animation frames are not guaranteed to a window that is not in front.
|
||||||
async function visible(page, selector, timeout = 15000) {
|
async function visible(page, selector, timeout = 15000) {
|
||||||
await page.waitForSelector(selector, { state: "visible", timeout });
|
await page
|
||||||
|
.waitForFunction(
|
||||||
|
(sel) => {
|
||||||
|
const el = document.querySelector(sel);
|
||||||
|
if (document.readyState !== "complete" || !el) return false;
|
||||||
|
if (el.closest(".hidden")) return false;
|
||||||
|
if (getComputedStyle(el).visibility !== "visible") return false;
|
||||||
|
const r = el.getBoundingClientRect();
|
||||||
|
return r.width > 0 && r.height > 0;
|
||||||
|
},
|
||||||
|
selector,
|
||||||
|
{ polling: 50, timeout },
|
||||||
|
)
|
||||||
|
.catch((e) => {
|
||||||
|
throw new Error(
|
||||||
|
"the page did not show " + selector + ": " + e.message,
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// An empty WebAssembly module: magic number and version header, no
|
// An empty WebAssembly module: magic number and version header, no
|
||||||
|
|||||||
@@ -113,6 +113,18 @@ test("the popup is drawn in the monospace font it declares (#418)", async (env)
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// The same stylesheet sets the size on body to 75%, which would draw the
|
||||||
|
// popup at 12px.
|
||||||
|
test("the popup's text is drawn at the 14px text-sm declares (#456)", async (env) => {
|
||||||
|
const size = await env.page.evaluate(
|
||||||
|
() => getComputedStyle(document.body).fontSize,
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
size === "14px",
|
||||||
|
"the popup's text is drawn at " + size + ", not at the 14px of text-sm",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// The empirical half of #182. The manifest change is only a claim about
|
// The empirical half of #182. The manifest change is only a claim about
|
||||||
// what the CSP permits; this is the observation. Two things have to hold
|
// what the CSP permits; this is the observation. Two things have to hold
|
||||||
// together, and the run covers both: the popup realm compiles WASM (here),
|
// together, and the run covers both: the popup realm compiles WASM (here),
|
||||||
@@ -4538,6 +4550,42 @@ test("a site's network switch changes nothing until the user approves it (#408)"
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Switching the network in Settings tells the page too, as an approved site
|
||||||
|
// request does (https://git.eeqj.de/sneak/AutistMask/issues/500). The wallet
|
||||||
|
// goes back to mainnet the same way at the end.
|
||||||
|
test("a network switch in Settings tells the page (#500)", async (env) => {
|
||||||
|
const { mainnet, sepolia } = NETWORKS;
|
||||||
|
const before = await storedNetwork(env.page);
|
||||||
|
assert(
|
||||||
|
before.networkId === "mainnet",
|
||||||
|
"this test starts on mainnet, not on " + before.networkId,
|
||||||
|
);
|
||||||
|
const eventsBefore = (await chainChangedEvents(env.dapp)).length;
|
||||||
|
await openSettings(env.page);
|
||||||
|
|
||||||
|
await env.page.selectOption("#settings-network", "sepolia");
|
||||||
|
let events = await chainChangedEvents(env.dapp, eventsBefore + 1);
|
||||||
|
assert(
|
||||||
|
events.length === eventsBefore + 1 &&
|
||||||
|
events[events.length - 1].data === sepolia.chainId,
|
||||||
|
"the page was not told of the switch to Sepolia: " +
|
||||||
|
JSON.stringify(events),
|
||||||
|
);
|
||||||
|
|
||||||
|
await env.page.selectOption("#settings-network", "mainnet");
|
||||||
|
events = await chainChangedEvents(env.dapp, eventsBefore + 2);
|
||||||
|
assert(
|
||||||
|
events.length === eventsBefore + 2 &&
|
||||||
|
events[events.length - 1].data === mainnet.chainId,
|
||||||
|
"the page was not told of the switch back to mainnet: " +
|
||||||
|
JSON.stringify(events),
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
isDeepStrictEqual(await storedNetwork(env.page), before),
|
||||||
|
"switching back did not restore the mainnet network and endpoints",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// The closing pass over both boundaries at once. Every message the section
|
// The closing pass over both boundaries at once. Every message the section
|
||||||
// put on either channel is re-read here and required to be free of the
|
// put on either channel is re-read here and required to be free of the
|
||||||
// password — and required to be there at all, method by method, so the
|
// password — and required to be there at all, method by method, so the
|
||||||
|
|||||||
@@ -0,0 +1,495 @@
|
|||||||
|
// A transaction approval and a signature approval the user leaves open for
|
||||||
|
// seven minutes are still answered, and the site receives both results
|
||||||
|
// (https://git.eeqj.de/sneak/AutistMask/issues/540).
|
||||||
|
//
|
||||||
|
// Both approvals, and the site's requests waiting on them, live only in the
|
||||||
|
// background worker's memory. With nothing else going on, Chrome stopped that
|
||||||
|
// worker about six minutes after the site's request, while the window was
|
||||||
|
// still open, and the user's answer then reached nobody. The approval window
|
||||||
|
// now posts on its approval port every 20 seconds, which keeps the worker
|
||||||
|
// running (src/popup/views/approval.js, show()).
|
||||||
|
//
|
||||||
|
// A separate program from run.js, and not driven by Playwright: Playwright
|
||||||
|
// keeps DevTools attached to the background worker, and Chrome never stops a
|
||||||
|
// worker DevTools is attached to, so in run.js the worker outlives any wait
|
||||||
|
// and a wait there proves nothing. This program starts Chromium itself and
|
||||||
|
// speaks the DevTools protocol over the pipe Chromium opens for it
|
||||||
|
// (--remote-debugging-pipe), attaching to pages only, never to the worker.
|
||||||
|
// Before the approvals are raised it watches the worker stop on its own, so a
|
||||||
|
// run in which something else keeps the worker running cannot pass.
|
||||||
|
//
|
||||||
|
// The dApp page and the stub node are the Firefox suite's loopback ones
|
||||||
|
// (tests/e2e/firefox/dapp.js). The site is connected and the node chosen
|
||||||
|
// through the extension's own screens, so nothing is written to its storage
|
||||||
|
// from outside.
|
||||||
|
//
|
||||||
|
// Run through script/test-e2e, which builds the extension and the pinned
|
||||||
|
// container.
|
||||||
|
//
|
||||||
|
// node tests/e2e/slowApproval.js
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const fs = require("fs");
|
||||||
|
const os = require("os");
|
||||||
|
const path = require("path");
|
||||||
|
const { spawn } = require("child_process");
|
||||||
|
|
||||||
|
const { chromium } = require("playwright-core");
|
||||||
|
const {
|
||||||
|
Transaction,
|
||||||
|
getAddress,
|
||||||
|
getBytes,
|
||||||
|
hexlify,
|
||||||
|
parseEther,
|
||||||
|
toQuantity,
|
||||||
|
toUtf8Bytes,
|
||||||
|
verifyMessage,
|
||||||
|
} = require("ethers");
|
||||||
|
|
||||||
|
const { PASSWORD } = require("./harness");
|
||||||
|
const { STUB_COUNTERPARTY } = require("./network");
|
||||||
|
const { startDappServer } = require("./firefox/dapp");
|
||||||
|
|
||||||
|
const DIST_CHROME = path.resolve(__dirname, "..", "..", "dist", "chrome");
|
||||||
|
|
||||||
|
// Chrome stopped the worker six minutes after the site's request when nothing
|
||||||
|
// kept it running, so the approvals are left open for longer than that.
|
||||||
|
const APPROVAL_WAIT_MS = 7 * 60 * 1000;
|
||||||
|
|
||||||
|
// With nothing pending, Chrome stops the worker 30 seconds after its last
|
||||||
|
// event; this is how long the program waits to see that.
|
||||||
|
const IDLE_STOP_TIMEOUT_MS = 90000;
|
||||||
|
|
||||||
|
const SIGN_HEX = hexlify(toUtf8Bytes("AutistMask e2e: a slow signature"));
|
||||||
|
|
||||||
|
const checks = [];
|
||||||
|
let failed = 0;
|
||||||
|
|
||||||
|
function check(name, cond, detail) {
|
||||||
|
checks.push(name);
|
||||||
|
if (cond) {
|
||||||
|
console.log("ok " + checks.length + " - " + name);
|
||||||
|
} else {
|
||||||
|
failed += 1;
|
||||||
|
console.log("not ok " + checks.length + " - " + name);
|
||||||
|
if (detail) console.log(" " + detail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sleep(ms) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Poll `probe` until it returns something truthy, and return that.
|
||||||
|
async function until(what, probe, timeout = 30000) {
|
||||||
|
const deadline = Date.now() + timeout;
|
||||||
|
for (;;) {
|
||||||
|
const value = await probe().catch(() => null);
|
||||||
|
if (value) return value;
|
||||||
|
if (Date.now() > deadline) {
|
||||||
|
throw new Error(
|
||||||
|
"gave up after " + timeout + "ms waiting for " + what,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await sleep(250);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The DevTools protocol over Chromium's pipe: commands go to its fd 3, and
|
||||||
|
// replies and events come back on its fd 4, each one JSON message ended by a
|
||||||
|
// NUL byte. Events are not used and are dropped. Returns send(method, params,
|
||||||
|
// sessionId), which resolves with the command's result.
|
||||||
|
function devtools(browser) {
|
||||||
|
const waiting = new Map();
|
||||||
|
let nextId = 1;
|
||||||
|
let pending = "";
|
||||||
|
const replies = browser.stdio[4];
|
||||||
|
replies.setEncoding("utf8");
|
||||||
|
replies.on("data", (chunk) => {
|
||||||
|
pending += chunk;
|
||||||
|
let end;
|
||||||
|
while ((end = pending.indexOf("\0")) !== -1) {
|
||||||
|
const message = JSON.parse(pending.slice(0, end));
|
||||||
|
pending = pending.slice(end + 1);
|
||||||
|
const caller = waiting.get(message.id);
|
||||||
|
if (!caller) continue;
|
||||||
|
waiting.delete(message.id);
|
||||||
|
if (message.error) {
|
||||||
|
caller.reject(
|
||||||
|
new Error(caller.method + ": " + message.error.message),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
caller.resolve(message.result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
replies.on("close", () => {
|
||||||
|
for (const caller of waiting.values()) {
|
||||||
|
caller.reject(new Error("the browser exited"));
|
||||||
|
}
|
||||||
|
waiting.clear();
|
||||||
|
});
|
||||||
|
return (method, params = {}, sessionId) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
const id = nextId++;
|
||||||
|
waiting.set(id, { method, resolve, reject });
|
||||||
|
browser.stdio[3].write(
|
||||||
|
JSON.stringify({ id, method, params, sessionId }) + "\0",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attach to a page and return a function that evaluates an expression in it,
|
||||||
|
// awaiting a promise it returns, and resolves with the value.
|
||||||
|
async function attach(send, targetId) {
|
||||||
|
const { sessionId } = await send("Target.attachToTarget", {
|
||||||
|
targetId,
|
||||||
|
flatten: true,
|
||||||
|
});
|
||||||
|
return async (expression) => {
|
||||||
|
const r = await send(
|
||||||
|
"Runtime.evaluate",
|
||||||
|
{ expression, awaitPromise: true, returnByValue: true },
|
||||||
|
sessionId,
|
||||||
|
);
|
||||||
|
if (r.exceptionDetails) {
|
||||||
|
throw new Error(
|
||||||
|
"evaluating " +
|
||||||
|
expression.slice(0, 80) +
|
||||||
|
" threw: " +
|
||||||
|
JSON.stringify(r.exceptionDetails.exception || {}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return r.result.value;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whether the page has loaded and shows the element with this id: the
|
||||||
|
// `hidden` class showView() keeps on every other view is on neither it nor
|
||||||
|
// anything around it.
|
||||||
|
function shows(id) {
|
||||||
|
return (
|
||||||
|
"document.readyState === 'complete' &&" +
|
||||||
|
" !!document.getElementById(" +
|
||||||
|
JSON.stringify(id) +
|
||||||
|
") && !document.getElementById(" +
|
||||||
|
JSON.stringify(id) +
|
||||||
|
").closest('.hidden')"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set an input's value and fire the input event typing would fire.
|
||||||
|
function typeInto(id, value) {
|
||||||
|
return (
|
||||||
|
"(() => { const el = document.getElementById(" +
|
||||||
|
JSON.stringify(id) +
|
||||||
|
"); el.value = " +
|
||||||
|
JSON.stringify(value) +
|
||||||
|
"; el.dispatchEvent(new Event('input', { bubbles: true })); })()"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function click(id) {
|
||||||
|
return "document.getElementById(" + JSON.stringify(id) + ").click()";
|
||||||
|
}
|
||||||
|
|
||||||
|
// The outcome of a request the dApp page started with __dapp.start(), or
|
||||||
|
// {settled: "pending"} if it has not settled within `timeout`.
|
||||||
|
function settled(key, timeout = 30000) {
|
||||||
|
return (
|
||||||
|
"Promise.race([window.__dapp.settle(" +
|
||||||
|
JSON.stringify(key) +
|
||||||
|
"), new Promise((r) => setTimeout(() => r({ settled: 'pending' }), " +
|
||||||
|
timeout +
|
||||||
|
"))])"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
if (!fs.existsSync(path.join(DIST_CHROME, "manifest.json"))) {
|
||||||
|
console.error(
|
||||||
|
"slowApproval: no unpacked build at " +
|
||||||
|
DIST_CHROME +
|
||||||
|
" — run make build first",
|
||||||
|
);
|
||||||
|
process.exitCode = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const node = await startDappServer();
|
||||||
|
const profile = fs.mkdtempSync(
|
||||||
|
path.join(os.tmpdir(), "autistmask-slow-approval-"),
|
||||||
|
);
|
||||||
|
const browser = spawn(
|
||||||
|
chromium.executablePath(),
|
||||||
|
[
|
||||||
|
"--headless",
|
||||||
|
// The container runs unprivileged, as in harness.js.
|
||||||
|
"--no-sandbox",
|
||||||
|
"--remote-debugging-pipe",
|
||||||
|
"--user-data-dir=" + profile,
|
||||||
|
"--disable-extensions-except=" + DIST_CHROME,
|
||||||
|
"--load-extension=" + DIST_CHROME,
|
||||||
|
// Nothing but the loopback dApp page and stub node can be reached.
|
||||||
|
"--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1",
|
||||||
|
"about:blank",
|
||||||
|
],
|
||||||
|
{ stdio: ["ignore", "ignore", "ignore", "pipe", "pipe"] },
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const send = devtools(browser);
|
||||||
|
const targets = async () =>
|
||||||
|
(await send("Target.getTargets")).targetInfos;
|
||||||
|
|
||||||
|
const worker = await until("the background worker", async () =>
|
||||||
|
(await targets()).find(
|
||||||
|
(t) =>
|
||||||
|
t.type === "service_worker" &&
|
||||||
|
t.url.startsWith("chrome-extension://"),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// The extension id is the host of the worker's URL, as in harness.js.
|
||||||
|
const popupUrl =
|
||||||
|
"chrome-extension://" +
|
||||||
|
new URL(worker.url).host +
|
||||||
|
"/src/popup/index.html";
|
||||||
|
const workerRunning = async () =>
|
||||||
|
(await targets()).some((t) => t.url === worker.url);
|
||||||
|
const openPage = async (url) => {
|
||||||
|
const { targetId } = await send("Target.createTarget", { url });
|
||||||
|
return { targetId, evaluate: await attach(send, targetId) };
|
||||||
|
};
|
||||||
|
const approvalPages = async () =>
|
||||||
|
(await targets()).filter(
|
||||||
|
(t) => t.type === "page" && t.url.includes("?approval="),
|
||||||
|
);
|
||||||
|
|
||||||
|
// A wallet, through the popup's own screens, and the stub node as its
|
||||||
|
// RPC endpoint, through Settings.
|
||||||
|
const popup = await openPage(popupUrl);
|
||||||
|
await until("the welcome screen", () =>
|
||||||
|
popup.evaluate(shows("view-welcome")),
|
||||||
|
);
|
||||||
|
await popup.evaluate(click("btn-welcome-add"));
|
||||||
|
await until("the add wallet screen", () =>
|
||||||
|
popup.evaluate(shows("view-add-wallet")),
|
||||||
|
);
|
||||||
|
await popup.evaluate(click("btn-generate-phrase"));
|
||||||
|
await until("a generated recovery phrase", () =>
|
||||||
|
popup.evaluate(
|
||||||
|
"document.getElementById('wallet-mnemonic').value.trim()" +
|
||||||
|
".split(/\\s+/).length >= 12",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await popup.evaluate(typeInto("add-wallet-password", PASSWORD));
|
||||||
|
await popup.evaluate(typeInto("add-wallet-password-confirm", PASSWORD));
|
||||||
|
await popup.evaluate(click("btn-add-wallet-confirm"));
|
||||||
|
await until(
|
||||||
|
"the main screen",
|
||||||
|
() => popup.evaluate(shows("view-main")),
|
||||||
|
60000,
|
||||||
|
);
|
||||||
|
await popup.evaluate(click("btn-settings"));
|
||||||
|
await until("the settings screen", () =>
|
||||||
|
popup.evaluate(shows("view-settings")),
|
||||||
|
);
|
||||||
|
await popup.evaluate(typeInto("settings-rpc", node.rpcUrl));
|
||||||
|
await popup.evaluate(click("btn-save-rpc"));
|
||||||
|
await until("the stub node saved as the RPC endpoint", () =>
|
||||||
|
popup.evaluate(
|
||||||
|
"new Promise((resolve) => chrome.storage.local.get(" +
|
||||||
|
"'autistmask', (r) => resolve(r.autistmask.rpcUrl === " +
|
||||||
|
JSON.stringify(node.rpcUrl) +
|
||||||
|
")))",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await send("Target.closeTarget", { targetId: popup.targetId });
|
||||||
|
|
||||||
|
// The site, connected through the real prompt with "Remember", so
|
||||||
|
// the connection is stored rather than held by the worker.
|
||||||
|
const dapp = await openPage(node.url);
|
||||||
|
await until("the injected provider", () =>
|
||||||
|
dapp.evaluate("!!window.ethereum && !!window.__dapp"),
|
||||||
|
);
|
||||||
|
await dapp.evaluate(
|
||||||
|
"window.__dapp.start('accounts', 'eth_requestAccounts', [])",
|
||||||
|
);
|
||||||
|
const prompt = await until(
|
||||||
|
"the connection prompt",
|
||||||
|
async () => (await approvalPages())[0],
|
||||||
|
);
|
||||||
|
const inPrompt = await attach(send, prompt.targetId);
|
||||||
|
await until("the connection prompt's screen", () =>
|
||||||
|
inPrompt(shows("view-approve-site")),
|
||||||
|
);
|
||||||
|
await inPrompt(
|
||||||
|
"document.getElementById('approve-remember').checked = true",
|
||||||
|
);
|
||||||
|
// The prompt closes itself on the click.
|
||||||
|
await inPrompt(click("btn-approve")).catch(() => {});
|
||||||
|
const accounts = await dapp.evaluate(settled("accounts"));
|
||||||
|
if (accounts.settled !== "resolved") {
|
||||||
|
throw new Error(
|
||||||
|
"the site could not be connected: " + JSON.stringify(accounts),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const address = getAddress(accounts.result[0]);
|
||||||
|
console.log("# address " + address + ", site " + node.origin);
|
||||||
|
|
||||||
|
// The control: with nothing pending, the worker stops on its own.
|
||||||
|
// Were something else keeping it running, the wait below would
|
||||||
|
// prove nothing.
|
||||||
|
const idleStart = Date.now();
|
||||||
|
const stoppedWhenIdle = await until(
|
||||||
|
"the idle worker to stop",
|
||||||
|
async () => !(await workerRunning()),
|
||||||
|
IDLE_STOP_TIMEOUT_MS,
|
||||||
|
).catch(() => false);
|
||||||
|
check(
|
||||||
|
"with nothing pending, Chrome stops the background worker on its own",
|
||||||
|
stoppedWhenIdle,
|
||||||
|
"the worker was still running " +
|
||||||
|
IDLE_STOP_TIMEOUT_MS / 1000 +
|
||||||
|
"s after its last event, so something other than the " +
|
||||||
|
"approval windows is keeping it running",
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
"# idle worker stopped after " +
|
||||||
|
Math.round((Date.now() - idleStart) / 1000) +
|
||||||
|
"s",
|
||||||
|
);
|
||||||
|
|
||||||
|
// A transaction approval and a signature approval, both open at once.
|
||||||
|
await dapp.evaluate(
|
||||||
|
"window.__dapp.start('tx', 'eth_sendTransaction', [" +
|
||||||
|
JSON.stringify({
|
||||||
|
from: address,
|
||||||
|
to: STUB_COUNTERPARTY,
|
||||||
|
value: toQuantity(parseEther("0.01")),
|
||||||
|
}) +
|
||||||
|
"])",
|
||||||
|
);
|
||||||
|
await until("the transaction approval window", async () =>
|
||||||
|
(await approvalPages()).length === 1 ? true : null,
|
||||||
|
);
|
||||||
|
await dapp.evaluate(
|
||||||
|
"window.__dapp.start('sign', 'personal_sign', [" +
|
||||||
|
JSON.stringify(SIGN_HEX) +
|
||||||
|
", " +
|
||||||
|
JSON.stringify(address) +
|
||||||
|
"])",
|
||||||
|
);
|
||||||
|
const windows = await until("both approval windows", async () => {
|
||||||
|
const pages = await approvalPages();
|
||||||
|
return pages.length === 2 ? pages : null;
|
||||||
|
});
|
||||||
|
let txWindow = null;
|
||||||
|
let signWindow = null;
|
||||||
|
for (const page of windows) {
|
||||||
|
const evaluate = await attach(send, page.targetId);
|
||||||
|
const view = await until("an approval screen", () =>
|
||||||
|
evaluate(
|
||||||
|
"(" +
|
||||||
|
shows("view-approve-tx") +
|
||||||
|
") ? 'tx' : (" +
|
||||||
|
shows("view-approve-sign") +
|
||||||
|
") ? 'sign' : null",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (view === "tx") txWindow = evaluate;
|
||||||
|
if (view === "sign") signWindow = evaluate;
|
||||||
|
}
|
||||||
|
if (!txWindow || !signWindow) {
|
||||||
|
throw new Error("the two windows are not one of each kind");
|
||||||
|
}
|
||||||
|
|
||||||
|
// The user takes seven minutes. The worker is checked every two
|
||||||
|
// seconds, and the wait ends early if Chrome stops it.
|
||||||
|
const opened = Date.now();
|
||||||
|
let stoppedAfter = null;
|
||||||
|
while (Date.now() - opened < APPROVAL_WAIT_MS) {
|
||||||
|
if (!(await workerRunning())) {
|
||||||
|
stoppedAfter = Math.round((Date.now() - opened) / 1000);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await sleep(2000);
|
||||||
|
}
|
||||||
|
check(
|
||||||
|
"the background worker keeps running while both approvals are open",
|
||||||
|
stoppedAfter === null,
|
||||||
|
"Chrome stopped the worker " +
|
||||||
|
stoppedAfter +
|
||||||
|
"s after the approvals opened",
|
||||||
|
);
|
||||||
|
|
||||||
|
await txWindow(typeInto("approve-tx-password", PASSWORD));
|
||||||
|
await txWindow(click("btn-approve-tx"));
|
||||||
|
await signWindow(typeInto("approve-sign-password", PASSWORD));
|
||||||
|
// The window closes itself once the signature is handed over.
|
||||||
|
await signWindow(click("btn-approve-sign")).catch(() => {});
|
||||||
|
|
||||||
|
const tx = await dapp.evaluate(settled("tx"));
|
||||||
|
const broadcast = node.broadcast.map((raw) => Transaction.from(raw));
|
||||||
|
check(
|
||||||
|
"the transaction approved after seven minutes reaches the site",
|
||||||
|
tx.settled === "resolved" &&
|
||||||
|
broadcast.length === 1 &&
|
||||||
|
tx.result === broadcast[0].hash &&
|
||||||
|
getAddress(broadcast[0].from) === address,
|
||||||
|
"the page got " +
|
||||||
|
JSON.stringify(tx) +
|
||||||
|
" and the node received " +
|
||||||
|
broadcast.length +
|
||||||
|
" transaction(s)",
|
||||||
|
);
|
||||||
|
|
||||||
|
const sign = await dapp.evaluate(settled("sign"));
|
||||||
|
check(
|
||||||
|
"the signature approved after seven minutes reaches the site",
|
||||||
|
sign.settled === "resolved" &&
|
||||||
|
getAddress(verifyMessage(getBytes(SIGN_HEX), sign.result)) ===
|
||||||
|
address,
|
||||||
|
"the page got " + JSON.stringify(sign),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
failed += 1;
|
||||||
|
console.log("# ERROR: " + (e && e.stack ? e.stack : e));
|
||||||
|
} finally {
|
||||||
|
if (browser.exitCode === null && browser.signalCode === null) {
|
||||||
|
const exited = new Promise((resolve) =>
|
||||||
|
browser.once("exit", resolve),
|
||||||
|
);
|
||||||
|
browser.kill();
|
||||||
|
await exited;
|
||||||
|
}
|
||||||
|
await node.close();
|
||||||
|
// Chromium's helper processes can still be writing to the profile
|
||||||
|
// for a moment after the browser process itself has exited.
|
||||||
|
fs.rmSync(profile, { recursive: true, force: true, maxRetries: 5 });
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("1.." + checks.length);
|
||||||
|
if (checks.length === 0) {
|
||||||
|
console.log("# FAILED: this program asserted nothing");
|
||||||
|
process.exitCode = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(
|
||||||
|
"# " +
|
||||||
|
(checks.length - failed) +
|
||||||
|
"/" +
|
||||||
|
checks.length +
|
||||||
|
" checks passed",
|
||||||
|
);
|
||||||
|
if (failed > 0) {
|
||||||
|
console.log("# FAILED");
|
||||||
|
process.exitCode = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((e) => {
|
||||||
|
console.error("slowApproval: " + (e && e.stack ? e.stack : e));
|
||||||
|
process.exitCode = 1;
|
||||||
|
});
|
||||||
@@ -89,6 +89,12 @@ describe("vendored blocklist", () => {
|
|||||||
expect(isPhishingDomain(LISTED[0].toUpperCase())).toBe(true);
|
expect(isPhishingDomain(LISTED[0].toUpperCase())).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("a hostname ending in a dot is the same host", () => {
|
||||||
|
expect(isPhishingDomain(LISTED[1] + ".")).toBe(true);
|
||||||
|
expect(isPhishingDomain("wallet." + LISTED[1] + ".")).toBe(true);
|
||||||
|
expect(isPhishingDomain(CLEAN[0] + ".")).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
test("returns false for an empty or missing hostname", () => {
|
test("returns false for an empty or missing hostname", () => {
|
||||||
expect(isPhishingDomain("")).toBe(false);
|
expect(isPhishingDomain("")).toBe(false);
|
||||||
expect(isPhishingDomain(null)).toBe(false);
|
expect(isPhishingDomain(null)).toBe(false);
|
||||||
@@ -133,6 +139,13 @@ describe("hostnameVariants", () => {
|
|||||||
test("lowercases hostnames", () => {
|
test("lowercases hostnames", () => {
|
||||||
expect(hostnameVariants("Evil.COM")).toEqual(["evil.com"]);
|
expect(hostnameVariants("Evil.COM")).toEqual(["evil.com"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("drops the trailing dot of a fully qualified hostname", () => {
|
||||||
|
expect(hostnameVariants("sub.evil.com.")).toEqual([
|
||||||
|
"sub.evil.com",
|
||||||
|
"evil.com",
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("domain hashing", () => {
|
describe("domain hashing", () => {
|
||||||
|
|||||||
@@ -240,6 +240,7 @@ function request(data) {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
state.trackedTokens = [];
|
state.trackedTokens = [];
|
||||||
state.wallets = [];
|
state.wallets = [];
|
||||||
|
state.networkId = "mainnet";
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("a token permission is warned about, naming spender and amount", () => {
|
describe("a token permission is warned about, naming spender and amount", () => {
|
||||||
@@ -532,3 +533,66 @@ describe("the sign screen refuses a mismatched primary type", () => {
|
|||||||
expect(node("btn-approve-sign").disabled).toBe(true);
|
expect(node("btn-approve-sign").disabled).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// EIP-712: a wallet refuses typed data whose domain names a chain other than
|
||||||
|
// the active one, because the signature is valid on the chain it names
|
||||||
|
// (https://git.eeqj.de/sneak/AutistMask/issues/519). The wallet is on Sepolia
|
||||||
|
// and the site asks for a mainnet USDC Permit.
|
||||||
|
describe("the sign screen refuses typed data for another chain", () => {
|
||||||
|
const REFUSAL =
|
||||||
|
"This typed data is for chain id 1, but the active network is Sepolia Testnet (chain id 11155111), so it cannot be signed.";
|
||||||
|
|
||||||
|
function withChainId(chainId) {
|
||||||
|
return { ...PERMIT, domain: { ...PERMIT.domain, chainId } };
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
decryptWithPassword.mockClear();
|
||||||
|
state.networkId = "sepolia";
|
||||||
|
});
|
||||||
|
|
||||||
|
test("another chain shows the error, with Sign disabled", async () => {
|
||||||
|
await openSignScreen(PERMIT);
|
||||||
|
expect(node("approve-sign-error").textContent).toBe(REFUSAL);
|
||||||
|
expect(node("btn-approve-sign").disabled).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Sign clicked anyway decrypts and signs nothing", async () => {
|
||||||
|
const sent = await openSignScreen(PERMIT);
|
||||||
|
node("approve-sign-password").value = "any password";
|
||||||
|
await click("btn-approve-sign");
|
||||||
|
|
||||||
|
expect(decryptWithPassword).not.toHaveBeenCalled();
|
||||||
|
expect(sent.map((msg) => msg.type)).not.toContain(
|
||||||
|
"AUTISTMASK_SIGN_RESPONSE",
|
||||||
|
);
|
||||||
|
expect(node("approve-sign-error").textContent).toBe(REFUSAL);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ethers signs 1, "1" and "0x1" as the same chain id.
|
||||||
|
test("the chain id is refused in each form ethers signs", () => {
|
||||||
|
for (const chainId of [1, "1", "0x1"]) {
|
||||||
|
expect(typedDataRefusal(request(withChainId(chainId)))).toBe(
|
||||||
|
REFUSAL,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a chain id that is not a number is refused", () => {
|
||||||
|
expect(typedDataRefusal(request(withChainId("mainnet")))).toBe(
|
||||||
|
"This typed data cannot be read, so it cannot be signed.",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the active chain leaves Sign enabled", async () => {
|
||||||
|
await openSignScreen(withChainId("0xaa36a7"));
|
||||||
|
expect(node("approve-sign-error").textContent).toBe("");
|
||||||
|
expect(node("btn-approve-sign").disabled).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("no chain id leaves Sign enabled", async () => {
|
||||||
|
await openSignScreen(withChainId(undefined));
|
||||||
|
expect(node("approve-sign-error").textContent).toBe("");
|
||||||
|
expect(node("btn-approve-sign").disabled).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -153,6 +153,18 @@ describe("the explanatory copy", () => {
|
|||||||
expect(all).not.toMatch(/\blost\b|\bstolen\b|\bgone\b/i);
|
expect(all).not.toMatch(/\blost\b|\bstolen\b|\bgone\b/i);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// The wallet holds the imported key but will not export it, so the copy
|
||||||
|
// must name every key the user may hold that reaches the addresses
|
||||||
|
// outside it.
|
||||||
|
test("it names the keys that reach the addresses outside this wallet", () => {
|
||||||
|
const body = defect.paragraphs.join(" ");
|
||||||
|
|
||||||
|
expect(body).toMatch(/private key export are disabled/);
|
||||||
|
expect(body).toMatch(
|
||||||
|
/with the extended private key you imported, if you kept a copy of it, or with the master extended private key or recovery phrase it came from, in software that repeats the same non-standard derivation/,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("it says the wallet is not deleted and what the user can do", () => {
|
test("it says the wallet is not deleted and what the user can do", () => {
|
||||||
const body = defect.paragraphs.join(" ");
|
const body = defect.paragraphs.join(" ");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user