@a11y-pulse/paste-blocking-audit 0.0.0-stage → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,166 @@
1
+ Copyright (c) 2026-present, A11y Pulse (https://www.a11ypulse.com/). All rights reserved.
2
+
3
+ # PolyForm Shield License 1.0.0
4
+
5
+ <https://polyformproject.org/licenses/shield/1.0.0>
6
+
7
+ ## Acceptance
8
+
9
+ In order to get any license under these terms, you must agree
10
+ to them as both strict obligations and conditions to all
11
+ your licenses.
12
+
13
+ ## Copyright License
14
+
15
+ The licensor grants you a copyright license for the
16
+ software to do everything you might do with the software
17
+ that would otherwise infringe the licensor's copyright
18
+ in it for any permitted purpose. However, you may
19
+ only distribute the software according to [Distribution
20
+ License](#distribution-license) and make changes or new works
21
+ based on the software according to [Changes and New Works
22
+ License](#changes-and-new-works-license).
23
+
24
+ ## Distribution License
25
+
26
+ The licensor grants you an additional copyright license
27
+ to distribute copies of the software. Your license
28
+ to distribute covers distributing the software with
29
+ changes and new works permitted by [Changes and New Works
30
+ License](#changes-and-new-works-license).
31
+
32
+ ## Notices
33
+
34
+ You must ensure that anyone who gets a copy of any part of
35
+ the software from you also gets a copy of these terms or the
36
+ URL for them above, as well as copies of any plain-text lines
37
+ beginning with `Required Notice:` that the licensor provided
38
+ with the software. For example:
39
+
40
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
41
+
42
+ ## Changes and New Works License
43
+
44
+ The licensor grants you an additional copyright license to
45
+ make changes and new works based on the software for any
46
+ permitted purpose.
47
+
48
+ ## Patent License
49
+
50
+ The licensor grants you a patent license for the software that
51
+ covers patent claims the licensor can license, or becomes able
52
+ to license, that you would infringe by using the software.
53
+
54
+ ## Noncompete
55
+
56
+ Any purpose is a permitted purpose, except for providing any
57
+ product that competes with the software or any product the
58
+ licensor or any of its affiliates provides using the software.
59
+
60
+ ## Competition
61
+
62
+ Goods and services compete even when they provide functionality
63
+ through different kinds of interfaces or for different technical
64
+ platforms. Applications can compete with services, libraries
65
+ with plugins, frameworks with development tools, and so on,
66
+ even if they're written in different programming languages
67
+ or for different computer architectures. Goods and services
68
+ compete even when provided free of charge. If you market a
69
+ product as a practical substitute for the software or another
70
+ product, it definitely competes.
71
+
72
+ ## New Products
73
+
74
+ If you are using the software to provide a product that does
75
+ not compete, but the licensor or any of its affiliates brings
76
+ your product into competition by providing a new version of
77
+ the software or another product using the software, you may
78
+ continue using versions of the software available under these
79
+ terms beforehand to provide your competing product, but not
80
+ any later versions.
81
+
82
+ ## Discontinued Products
83
+
84
+ You may begin using the software to compete with a product
85
+ or service that the licensor or any of its affiliates has
86
+ stopped providing, unless the licensor includes a plain-text
87
+ line beginning with `Licensor Line of Business:` with the
88
+ software that mentions that line of business. For example:
89
+
90
+ > Licensor Line of Business: YoyodyneCMS Content Management
91
+ System (http://example.com/cms)
92
+
93
+ ## Sales of Business
94
+
95
+ If the licensor or any of its affiliates sells a line of
96
+ business developing the software or using the software
97
+ to provide a product, the buyer can also enforce
98
+ [Noncompete](#noncompete) for that product.
99
+
100
+ ## Fair Use
101
+
102
+ You may have "fair use" rights for the software under the
103
+ law. These terms do not limit them.
104
+
105
+ ## No Other Rights
106
+
107
+ These terms do not allow you to sublicense or transfer any of
108
+ your licenses to anyone else, or prevent the licensor from
109
+ granting licenses to anyone else. These terms do not imply
110
+ any other licenses.
111
+
112
+ ## Patent Defense
113
+
114
+ If you make any written claim that the software infringes or
115
+ contributes to infringement of any patent, your patent license
116
+ for the software granted under these terms ends immediately. If
117
+ your company makes such a claim, your patent license ends
118
+ immediately for work on behalf of your company.
119
+
120
+ ## Violations
121
+
122
+ The first time you are notified in writing that you have
123
+ violated any of these terms, or done anything with the software
124
+ not covered by your licenses, your licenses can nonetheless
125
+ continue if you come into full compliance with these terms,
126
+ and take practical steps to correct past violations, within
127
+ 32 days of receiving notice. Otherwise, all your licenses
128
+ end immediately.
129
+
130
+ ## No Liability
131
+
132
+ ***As far as the law allows, the software comes as is, without
133
+ any warranty or condition, and the licensor will not be liable
134
+ to you for any damages arising out of these terms or the use
135
+ or nature of the software, under any kind of legal claim.***
136
+
137
+ ## Definitions
138
+
139
+ The **licensor** is the individual or entity offering these
140
+ terms, and the **software** is the software the licensor makes
141
+ available under these terms.
142
+
143
+ A **product** can be a good or service, or a combination
144
+ of them.
145
+
146
+ **You** refers to the individual or entity agreeing to these
147
+ terms.
148
+
149
+ **Your company** is any legal entity, sole proprietorship,
150
+ or other kind of organization that you work for, plus all
151
+ its affiliates.
152
+
153
+ **Affiliates** means the other organizations than an
154
+ organization has control over, is under the control of, or is
155
+ under common control with.
156
+
157
+ **Control** means ownership of substantially all the assets of
158
+ an entity, or the power to direct its management and policies
159
+ by vote, contract, or otherwise. Control can be direct or
160
+ indirect.
161
+
162
+ **Your licenses** are all the licenses granted to you for the
163
+ software under these terms.
164
+
165
+ **Use** means anything you do with the software requiring one
166
+ of your licenses.
package/README.md CHANGED
@@ -1,3 +1,228 @@
1
- # Temporary Holding Version
1
+ # @a11y-pulse/paste-blocking-audit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://img.shields.io/npm/v/@a11y-pulse/paste-blocking-audit)](https://www.npmjs.com/package/@a11y-pulse/paste-blocking-audit)
4
+ [![CI](https://github.com/A11y-Pulse/audits/actions/workflows/ci.yml/badge.svg)](https://github.com/A11y-Pulse/audits/actions/workflows/ci.yml)
5
+ [![License: PolyForm Shield 1.0.0](https://img.shields.io/badge/license-PolyForm%20Shield%201.0.0-blue)](./LICENSE.md)
6
+
7
+ An accessibility audit for [**WCAG 2.2: 3.3.8 Accessible Authentication (Minimum)**](https://www.w3.org/WAI/WCAG22/Understanding/accessible-authentication-minimum) (Level AA). Remembering a password or copying a code from one place to another is a cognitive function test, and a sign-in that depends on one must offer a way around it. For most sites that way is a password manager, or copy and paste. The audit finds the page's password, username and one-time-code fields and checks that nothing keeps a password manager or a paste out of them: an `onpaste="return false"`, a script that cancels the paste, a code split into boxes that takes one character of a pasted code, or `autocomplete` switched off.
8
+
9
+ Static analysis cannot see any of this. A paste handler added with `addEventListener` leaves no trace in the markup, so the audit pastes into each field and watches what the page does.
10
+
11
+ This audit was developed by [A11y Pulse](https://www.a11ypulse.com/) for its accessibility monitoring service. It is released as source-available under the [PolyForm Shield License 1.0.0](#license).
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @a11y-pulse/paste-blocking-audit @a11y-pulse/browser-adaptor puppeteer
17
+ ```
18
+
19
+ ## Quickstart
20
+
21
+ ```js
22
+ import { runPasteBlockingAudit } from "@a11y-pulse/paste-blocking-audit";
23
+ import { PuppeteerAdaptor } from "@a11y-pulse/browser-adaptor/puppeteer";
24
+ import puppeteer from "puppeteer";
25
+
26
+ const browser = await puppeteer.launch();
27
+ const page = await browser.newPage();
28
+ await page.goto("https://example.com/sign-in");
29
+
30
+ const result = await runPasteBlockingAudit(new PuppeteerAdaptor(page));
31
+
32
+ console.log(result.summary);
33
+ // { checked: 2, failed: 1, needsReview: 0, passed: 1, unchecked: 0 }
34
+
35
+ console.log(result.failed);
36
+ // [
37
+ // {
38
+ // selector: "#password",
39
+ // html: '<input id="password" type="password" name="password" onpaste="return false">',
40
+ // kind: "password",
41
+ // signals: ["paste-blocked"],
42
+ // blocked: ["paste"],
43
+ // detectedBy: "inline-handler",
44
+ // autocomplete: null,
45
+ // boxes: null
46
+ // }
47
+ // ]
48
+
49
+ await browser.close();
50
+ ```
51
+
52
+ A page with no authentication fields returns `summary.checked: 0`, which is inapplicable.
53
+
54
+ ## How it decides
55
+
56
+ ### Which fields are checked
57
+
58
+ Every rendered, enabled text-entry `<input>`, including those in open shadow roots, is considered in one call into the page:
59
+
60
+ | Kind | When |
61
+ | --- | --- |
62
+ | `password` | An `<input type="password">` |
63
+ | `new-password` | A password field in a form with two or more of them, or one with `autocomplete="new-password"` outside a sign-in form |
64
+ | `username` | A text, email or telephone field in the same form as a password field, when it is `type="email"`, has an `autocomplete` of `username`, `email` or `tel`, or its name, id, label or placeholder mentions a user name, email, login, account or phone |
65
+ | `one-time-code` | A field with `autocomplete="one-time-code"`; a field whose name, id, label or placeholder says OTP, one-time, verification code, passcode, 2FA, MFA, authentication code or "6-digit code"; a numeric field (`inputmode="numeric"`, `type="number"` or `"tel"`, or a digit `pattern`) that says "code"; or a run of four or more consecutive one-character boxes (`maxlength="1"`), reported at its first box |
66
+
67
+ Postcodes, promo, voucher and country codes, card security codes (`autocomplete="cc-…"`) and the like are not one-time codes. A field with no `<form>` is grouped by its nearest `fieldset`, dialog, `section` or `main`. A sign-in form is one whose only password field sits beside a button reading "Sign in" or "Log in".
68
+
69
+ ### How a paste is tried
70
+
71
+ For each field the audit dispatches, in order, a Ctrl+V and a Cmd+V `keydown`, a `beforeinput` event with `inputType: "insertFromPaste"`, and a `paste` event carrying text in its `clipboardData`. These are synthetic events: the browser inserts nothing for them, and the system clipboard is never read or written.
72
+
73
+ - An event the page cancels, with nothing written into the field in the next 150ms, is a refusal. It is recorded in `blocked` as `shortcut`, `beforeinput` or `paste`.
74
+ - An event the page cancels and then writes the text in itself, as a handler that trims whitespace or spreads a code across boxes does, is not a refusal. The audit puts the previous value back and announces it with an `input` event, so a framework holding the value in state follows. A page that only empties the field has not taken the paste, and is still a refusal.
75
+ - The fields are looked at once more 300ms after the last paste. A value that has turned up by then is put back, and the field is no longer counted as refusing: the page took the paste, only slowly.
76
+ - A refusal is tried once more with the field focused before it is believed, since a handler that inserts through the selection (`document.execCommand("insertText")`) only reaches the focused field. No other field is focused, so blur validation is not set off on fields that behave.
77
+ - A `readonly` field is focused to see whether a handler unlocks it. One that unlocks is pasted into and locked again; one that stays read-only is left alone.
78
+
79
+ `detectedBy` is `inline-handler` when the field or an ancestor has an `onpaste` attribute, and `event-listener` otherwise.
80
+
81
+ ### What is pasted
82
+
83
+ The text is shaped to the field, so that a field is not blamed for turning away text of the wrong kind:
84
+
85
+ | Field | Text pasted |
86
+ | --- | --- |
87
+ | Password | `Probe-4f9a-Paste`, cut to the field's `maxlength` |
88
+ | Username | `probe@example.com`, or `5550100` in a telephone or numeric field, cut to `maxlength` |
89
+ | One-time code, or a numeric password such as a PIN | Digits, **one fewer than the field takes**. The length comes from the number of boxes, `maxlength`, a `pattern` such as `\d{6}`, or wording such as "6-digit code"; with none of those, three digits are pasted |
90
+
91
+ A code is never pasted whole, because a page may verify a code the moment the field is full, and a wrong code sent to the server uses up an attempt or locks the account. `partialProbe` is true on these fields. The cost is that a page which cancels the paste of anything but a whole code looks the same as one that cancels every paste, so a cancelled paste on such a field is the review signal `partial-paste-refused` rather than `paste-blocked`.
92
+
93
+ ### Nothing is submitted or sent
94
+
95
+ A page that reacts to a paste by submitting or verifying would otherwise act on the audit's text. From the first paste until every value is back in place, the audit therefore:
96
+
97
+ - cancels every `submit` event before the page's own handlers see it, and replaces `HTMLFormElement.prototype.submit` and `requestSubmit` with functions that do nothing;
98
+ - replaces `fetch` with a function that rejects with an `AbortError`, `XMLHttpRequest.prototype.send` with one that fires `error`, and `navigator.sendBeacon` with one that sends nothing.
99
+
100
+ All of these are put back when the audit finishes, including when it throws. Whatever the page tried and was stopped from doing in response to a field's paste is listed in that field's `suppressed`, as `submit` or `request`. Focus, and the selection in the focused field, are returned to where they were.
101
+
102
+ ### Signals
103
+
104
+ | Signal | Bucket | When |
105
+ | --- | --- | --- |
106
+ | `paste-blocked` | `failed` | The page cancels the `paste` event and the field stays unchanged |
107
+ | `partial-paste-refused` | `needsReview` | The same, on a one-time code or numeric PIN, which is pasted a digit short. The page may only be turning away a code of the wrong length |
108
+ | `paste-may-be-blocked` | `needsReview` | The page cancels the paste key press or the `beforeinput` event, but not the `paste` event. A digits-only key filter that forgets modifier keys does this: Ctrl+V does nothing, while the context menu and a password manager still work |
109
+ | `split-code-paste-unhandled` | `needsReview` | A code split into one-character boxes neither cancels the paste nor fills its boxes, so a pasted code is cut to its first character |
110
+ | `readonly-until-focus` | `needsReview` | The field is `readonly` until focused, a trick for keeping autofill out |
111
+ | `autocomplete-off` | `needsReview` | `autocomplete="off"` on the field, or on its form when the field has none. Browsers ignore it for sign-in fields, but some password managers honour it, and it is sometimes legitimate |
112
+ | `new-password-on-sign-in` | `needsReview` | The password field of a sign-in form has `autocomplete="new-password"`, so a password manager suggests a new password instead of filling the saved one |
113
+ | `no-autofill-hint` | `needsReview` | A one-time-code field in a single box has no `autocomplete="one-time-code"`, so the browser does not offer the code from a text message |
114
+
115
+ `signals` lists every signal that applies, most serious first, and the first decides the bucket. A missing show-password button is not reported: it helps, but the criterion does not ask for it.
116
+
117
+ ### `failed` is not always a WCAG failure
118
+
119
+ A field that blocks pasting fails 3.3.8 only when the page offers no other way to sign in that needs nothing remembered or transcribed, such as a passkey, an emailed link or a third-party sign-in. The audit cannot see those, particularly when they sit on a later step. `failed` therefore means "nothing can be pasted into this field", which is a failure on the usual password-only sign-in. The A11y Pulse audit runner reports both `failed` and `needsReview` in `incomplete` for this reason, with blocked fields listed first.
120
+
121
+ ## Browser support
122
+
123
+ | Adaptor | Browser | Supported |
124
+ | --- | --- | --- |
125
+ | Puppeteer | Chrome | Yes |
126
+ | Playwright | Chromium | Yes |
127
+ | Playwright | WebKit | Yes |
128
+ | Playwright | Firefox | Yes |
129
+
130
+ ## Adaptor requirements
131
+
132
+ The audit uses `evaluate`, `evaluateHandle` and `disposeRef` to inspect the page and build selectors, and calls `ensureFocusReporting` first, so that focusing a field fires its handlers when the page is not in the foreground. It presses no keys and takes no screenshots.
133
+
134
+ ## Options
135
+
136
+ | Option | Type | Default | Description |
137
+ | --- | --- | --- | --- |
138
+ | `fieldLimit` | `number` | `50` | Max authentication fields to inspect. Fields past the limit are counted in `summary.unchecked`. |
139
+ | `reportLimit` | `number` | `10` | Max fields to list in each of `failed`, `needsReview` and `passed`. The summary still counts every field. |
140
+
141
+ ## Result shape
142
+
143
+ ```ts
144
+ type PasteBlockingField = {
145
+ /** For a split code, its first box. */
146
+ selector: string;
147
+ /** Truncated opening tag, with any typed value redacted. */
148
+ html: string;
149
+ kind: "password" | "new-password" | "username" | "one-time-code";
150
+ /** Every signal that applies, most serious first. Empty when the field passes. */
151
+ signals: (
152
+ | "paste-blocked"
153
+ | "partial-paste-refused"
154
+ | "paste-may-be-blocked"
155
+ | "split-code-paste-unhandled"
156
+ | "readonly-until-focus"
157
+ | "autocomplete-off"
158
+ | "new-password-on-sign-in"
159
+ | "no-autofill-hint"
160
+ )[];
161
+ /** What the page cancelled while leaving the field unchanged. */
162
+ blocked: ("paste" | "beforeinput" | "shortcut")[];
163
+ /** Where the refusal came from, or null when nothing was refused. */
164
+ detectedBy: "inline-handler" | "event-listener" | null;
165
+ /** The field's `autocomplete`, or its form's. Null if unset. */
166
+ autocomplete: string | null;
167
+ /** How many one-character boxes a split code has, or null. */
168
+ boxes: number | null;
169
+ /** The text pasted was a digit short of what the field takes, as for a code or PIN. */
170
+ partialProbe: boolean;
171
+ /** What the page tried to do in response to the paste and was stopped from doing. */
172
+ suppressed: ("submit" | "request")[];
173
+ };
174
+
175
+ type PasteBlockingResult = {
176
+ failed: PasteBlockingField[];
177
+ needsReview: PasteBlockingField[];
178
+ passed: PasteBlockingField[];
179
+ summary: {
180
+ checked: number;
181
+ failed: number;
182
+ needsReview: number;
183
+ passed: number;
184
+ unchecked: number;
185
+ };
186
+ };
187
+ ```
188
+
189
+ `classifyField(field)`, the pure classifier behind the audit, returns the `signals` and a `verdict` of `"failed"`, `"review"` or null for an inspected field.
190
+
191
+ ## Limitations
192
+
193
+ - **Synthetic events only.** The pasted events are not trusted, so a handler that checks `event.isTrusted` before cancelling is missed, and nothing confirms the result with a real paste: the adaptor has no paste primitive that leaves the system clipboard alone.
194
+ - **Clearing the field after the paste is missed.** A page that lets the paste through and then empties the field on `input` or `change` passes, because a synthetic paste inserts nothing for it to clear.
195
+ - **Password managers are not run.** `readonly-until-focus`, `autocomplete-off` and the other autofill signals are known ways of keeping one out, not an observation of one failing, which is why they are only reviewed.
196
+ - **Other ways to sign in are not looked for.** See [`failed` is not always a WCAG failure](#failed-is-not-always-a-wcag-failure).
197
+ - **`<input>` only.** Contenteditable fields and custom controls that draw their own text entry are not inspected, nor is a split code built without `maxlength="1"`.
198
+ - **English wording.** One-time-code and username fields are recognised by English words in their name, id, label or placeholder, and sign-in forms by an English button. `autocomplete` values and `type="password"` work in any language.
199
+ - **Dropping text is not tried.** Sites that block paste often block drop as well, but pages also cancel `drop` for unrelated reasons, so it says little.
200
+ - **Main document only.** Fields inside iframes, which is where many embedded sign-in widgets live, and closed shadow roots are not reached.
201
+ - **A whole code is never tried.** Because a code is pasted a digit short, a field that refuses every paste and one that refuses only an incomplete code both land in `needsReview` as `partial-paste-refused`.
202
+ - **Only the usual ways of sending are stopped.** Form submission, `fetch`, `XMLHttpRequest` and `sendBeacon` are held back while fields are pasted into. A page that sends pasted text some other way, over a WebSocket, by setting an image's `src` or by assigning `location`, is not stopped, though it would be sending an incomplete code. A page whose request was stopped sees it fail and may show its own error message.
203
+ - **A value written very late is missed.** A page that writes the pasted text in more than about 300ms after the last field was pasted into, as one waiting on a slow network call might, is past the final check: its field is reported as refusing and is left holding the audit's text.
204
+ - **The page is touched lightly.** A field is focused, and then blurred, only when it is `readonly` or refused a paste, and focus is then returned to where it was. A value the page wrote in response to a paste is put back and announced with an `input` event, which the page's own validation may react to.
205
+
206
+ ## Known false positives
207
+
208
+ Cases where the audit reports a problem that is not one. Each says which bucket it lands in.
209
+
210
+ In the A11y Pulse audit runner, both `failed` and `needsReview` are reported in `incomplete`.
211
+
212
+ - **A site with a passkey or emailed-link sign-in** (`failed`). Blocking paste on the password field is then poor practice rather than a 3.3.8 failure.
213
+ - **A paste handler that writes the text in very late, or not from the event** (`failed`). A handler that cancels the paste and inserts the text after a slow network call, later than the final check, or reads `navigator.clipboard` instead of the event, looks like a refusal.
214
+ - **A code field that takes only a whole code** (`needsReview`). A handler that cancels the paste of anything but a complete code refuses the audit's shortened one, and is reported as `partial-paste-refused`.
215
+ - **A numeric "security code" that is a card's** (`needsReview`). Without `autocomplete="cc-csc"` or a mention of the card, a numeric field labelled "Security code" is taken for a one-time code and reported for its missing autofill hint.
216
+ - **One-character boxes that are not a code** (`needsReview`). Four or more consecutive `maxlength="1"` fields, such as the squares of a word game or a date split into digits, are taken for a split code.
217
+ - **Deliberate `autocomplete="off"`** (`needsReview`). A one-time recovery code or a field on a shared kiosk may be right to switch autofill off.
218
+ - **A key filter with its own paste shortcut handling** (`needsReview`). A field that cancels every key press and reads Ctrl+V from the clipboard API itself is a `paste-may-be-blocked`.
219
+
220
+ ## License
221
+
222
+ Released under the [PolyForm Shield License 1.0.0](./LICENSE.md), in plain language:
223
+
224
+ - **Source-available.** The source is public and you can read, fork, and modify it.
225
+ - **Permitted for non-competing use.** You can use this package freely in your own products and services, as long as they don't compete with A11y Pulse.
226
+ - **Competing products are forbidden.** You may not use this software (or a modified version of it) to build a product or service that competes with A11y Pulse's accessibility monitoring offering.
227
+
228
+ See [LICENSE.md](./LICENSE.md) for the full, binding terms.
@@ -0,0 +1,18 @@
1
+ import { type BrowserAdaptor } from "@a11y-pulse/browser-adaptor";
2
+ import type { PasteBlockingResult } from "./result";
3
+ export declare const DEFAULT_FIELD_LIMIT = 50;
4
+ export declare const DEFAULT_REPORT_LIMIT = 10;
5
+ export type PasteBlockingOptions = {
6
+ /** Max authentication fields to inspect. Defaults to 50. */
7
+ fieldLimit?: number;
8
+ /** Max fields to report in each of `failed`, `needsReview` and `passed`. Defaults to 10. */
9
+ reportLimit?: number;
10
+ };
11
+ /**
12
+ * Find the page's password, username and one-time-code fields and check that nothing stops a
13
+ * password manager or a paste from filling them. Pastes are simulated with synthetic events and
14
+ * the clipboard is not touched. So that the page cannot act on the pasted text, a one-time code is
15
+ * pasted a digit short, and form submission and `fetch`, `XMLHttpRequest` and `sendBeacon` requests
16
+ * are stopped until every field value and the focus are back as they were found.
17
+ */
18
+ export declare function runPasteBlockingAudit(adaptor: BrowserAdaptor, options?: PasteBlockingOptions): Promise<PasteBlockingResult>;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * IMPORTANT: Functions in this file are serialized and injected into the audited page, so they must
3
+ * not reference any symbols outside their own scope.
4
+ */
5
+ /** What an authentication field takes. `new-password` is a password being chosen or confirmed. */
6
+ export type AuthFieldKind = "password" | "new-password" | "username" | "one-time-code";
7
+ /**
8
+ * A way the page refused a paste: it cancelled the `paste` event, cancelled the `beforeinput`
9
+ * event for a paste, or cancelled the Ctrl+V or Cmd+V key press.
10
+ */
11
+ export type BlockMechanism = "paste" | "beforeinput" | "shortcut";
12
+ /**
13
+ * Something the page tried to do while a field was being pasted into: submit a form (`submit`), or
14
+ * send a request with `fetch`, `XMLHttpRequest` or `navigator.sendBeacon` (`request`).
15
+ */
16
+ export type SuppressedAction = "submit" | "request";
17
+ export type InspectedField = {
18
+ kind: AuthFieldKind;
19
+ /** Shallow outerHTML. */
20
+ html: string;
21
+ /** The field's own `autocomplete`, lower-cased, or its form's when it has none. Null if unset. */
22
+ autocomplete: string | null;
23
+ /** Every way the page refused the paste, with the field left unchanged. */
24
+ blocked: BlockMechanism[];
25
+ /** An `onpaste` attribute on the field or an ancestor, as opposed to a script's listener. */
26
+ inlineHandler: boolean;
27
+ /** The page put the pasted text into the field itself. */
28
+ handled: boolean;
29
+ /** The field was `readonly` until it was focused. */
30
+ readonlyUntilFocus: boolean;
31
+ /** How many single-character boxes the field is split into, or 0 for an ordinary field. */
32
+ boxes: number;
33
+ /** A lone password field in a form whose submit button says "sign in" or "log in". */
34
+ signIn: boolean;
35
+ /**
36
+ * The pasted text was a digit short of what the field takes, as it is for a one-time code or a
37
+ * numeric PIN, so that the page cannot take it for a complete value and send it.
38
+ */
39
+ partialProbe: boolean;
40
+ /** What the page tried to do in response to the paste, and was stopped from doing. */
41
+ suppressed: SuppressedAction[];
42
+ };
43
+ export type AuthFieldInspection = {
44
+ fields: InspectedField[];
45
+ /** Every authentication field, including those past the limit. */
46
+ total: number;
47
+ };
48
+ /**
49
+ * Find every rendered password, username and one-time-code field, descending open shadow roots,
50
+ * and paste into each with synthetic events to see whether the page refuses. Any value the page
51
+ * writes in response is put back, including one written a moment later, and focus is returned to
52
+ * where it was. While the fields are pasted into, form submission and requests made with `fetch`,
53
+ * `XMLHttpRequest` and `sendBeacon` are stopped, and a one-time code is pasted a digit short, so
54
+ * the page cannot send the pasted text anywhere. The inspected elements are left on
55
+ * `window[stashKey]`, in the same order.
56
+ */
57
+ export declare function inspectAuthFieldsScript(stashKey: string, fieldLimit: number): Promise<AuthFieldInspection>;
@@ -0,0 +1,27 @@
1
+ import type { InspectedField } from "./browser-scripts";
2
+ /**
3
+ * What stands between the field and a password manager or a paste.
4
+ *
5
+ * - `paste-blocked`: the page cancels the `paste` event and the field stays empty.
6
+ * - `partial-paste-refused`: the page cancels the `paste` event for a one-time code or numeric PIN.
7
+ * The audit pastes those a digit short, so the page may only be turning away the wrong length.
8
+ * - `paste-may-be-blocked`: the page cancels only the paste key press or the `beforeinput` event.
9
+ * - `split-code-paste-unhandled`: a code split into one-character boxes takes one character of a
10
+ * pasted code.
11
+ * - `readonly-until-focus`: the field is `readonly` until focused, which hides it from autofill.
12
+ * - `autocomplete-off`: `autocomplete="off"` on the field or its form.
13
+ * - `new-password-on-sign-in`: `autocomplete="new-password"` on the password of a sign-in form.
14
+ * - `no-autofill-hint`: a one-time-code field without `autocomplete="one-time-code"`.
15
+ */
16
+ export type PasteBlockingSignal = "paste-blocked" | "partial-paste-refused" | "paste-may-be-blocked" | "split-code-paste-unhandled" | "readonly-until-focus" | "autocomplete-off" | "new-password-on-sign-in" | "no-autofill-hint";
17
+ export type Verdict = "failed" | "review";
18
+ export type FieldClassification = {
19
+ /** Every signal that applies, most serious first. Empty when the field passes. */
20
+ signals: PasteBlockingSignal[];
21
+ /** `failed` when the first signal is `paste-blocked`, `review` for any other, null for none. */
22
+ verdict: Verdict | null;
23
+ };
24
+ /**
25
+ * Decide what, if anything, stops a password manager or a paste from filling an inspected field.
26
+ */
27
+ export declare function classifyField(field: InspectedField): FieldClassification;
@@ -0,0 +1,7 @@
1
+ export type { BrowserAdaptor, ElementRef } from "@a11y-pulse/browser-adaptor";
2
+ export type { PasteBlockingOptions } from "./audit";
3
+ export { DEFAULT_FIELD_LIMIT, DEFAULT_REPORT_LIMIT, runPasteBlockingAudit } from "./audit";
4
+ export type { AuthFieldKind, BlockMechanism, InspectedField, SuppressedAction, } from "./browser-scripts";
5
+ export type { FieldClassification, PasteBlockingSignal, Verdict } from "./classify";
6
+ export { classifyField } from "./classify";
7
+ export type { PasteBlockDetection, PasteBlockingField, PasteBlockingResult } from "./result";
package/dist/index.js ADDED
@@ -0,0 +1,571 @@
1
+ // src/audit.ts
2
+ import {
3
+ releaseStashedElements,
4
+ stashedElementSelectors
5
+ } from "@a11y-pulse/browser-adaptor";
6
+ import { truncateHtml } from "@a11y-pulse/browser-adaptor/dom";
7
+
8
+ // src/browser-scripts.ts
9
+ async function inspectAuthFieldsScript(stashKey, fieldLimit) {
10
+ const TEXT_TYPES = /* @__PURE__ */ new Set(["text", "tel", "number", "email", "password", "search", "url"]);
11
+ const USERNAME_TYPES = /* @__PURE__ */ new Set(["text", "email", "tel"]);
12
+ const CODE_HINT = /\b(otp|totp|2fa|mfa|one time|verification code|verify code|auth code|authentication code|passcode|pass code|sms code|\d+ digit code)\b/;
13
+ const NOT_A_SIGN_IN_CODE = /\b(post|postal|postcode|zip|promo|coupon|discount|voucher|gift|country|area|referral|invite|card|cvv|cvc|product|sku|tracking|order|dial)\b/;
14
+ const USERNAME_HINT = /\b(user|username|email|e mail|login|account|phone|mobile)\b/;
15
+ const SIGN_IN = /\b(sign in|log in|login|signin)\b/;
16
+ const REFUSAL_WAIT_MS = 150;
17
+ const POLL_MS = 25;
18
+ const FINAL_SETTLE_MS = 300;
19
+ const RECHECK_MS = 100;
20
+ const isRendered = (el) => typeof el.checkVisibility === "function" ? el.checkVisibility({ visibilityProperty: true }) : el.getClientRects().length > 0;
21
+ const words = (text) => text.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
22
+ const inputsIn = (root) => {
23
+ const groups = [];
24
+ const own = [];
25
+ for (const el of root.querySelectorAll("*")) {
26
+ if (el instanceof HTMLInputElement) {
27
+ const type = el.type.toLowerCase();
28
+ if (TEXT_TYPES.has(type) && !el.disabled && isRendered(el)) {
29
+ own.push(el);
30
+ }
31
+ }
32
+ if (el.shadowRoot) {
33
+ groups.push(...inputsIn(el.shadowRoot));
34
+ }
35
+ }
36
+ return [own, ...groups];
37
+ };
38
+ const scopeOf = (el) => el.form ?? el.closest("[role=form], fieldset, dialog, [role=dialog], section, main") ?? el.getRootNode();
39
+ const autocompleteOf = (el) => {
40
+ const own = el.getAttribute("autocomplete")?.trim().toLowerCase();
41
+ if (own) {
42
+ return own;
43
+ }
44
+ return el.form?.getAttribute("autocomplete")?.trim().toLowerCase() || null;
45
+ };
46
+ const hintOf = (el) => {
47
+ const labels = Array.from(el.labels ?? [], (label) => label.textContent ?? "");
48
+ return words(
49
+ [
50
+ el.name,
51
+ el.id,
52
+ el.getAttribute("placeholder"),
53
+ el.getAttribute("aria-label"),
54
+ el.getAttribute("title"),
55
+ ...labels
56
+ ].join(" ")
57
+ );
58
+ };
59
+ const isNumeric = (el) => {
60
+ const pattern = el.getAttribute("pattern") ?? "";
61
+ return el.getAttribute("inputmode")?.toLowerCase() === "numeric" || el.type === "number" || el.type === "tel" || pattern.includes("\\d") || pattern.includes("0-9");
62
+ };
63
+ const isCodeField = (el) => {
64
+ const autocomplete = autocompleteOf(el) ?? "";
65
+ if (autocomplete.split(/\s+/).includes("one-time-code")) {
66
+ return true;
67
+ }
68
+ if (el.type === "password" || el.type === "email" || autocomplete.startsWith("cc-")) {
69
+ return false;
70
+ }
71
+ const hint = hintOf(el);
72
+ if (NOT_A_SIGN_IN_CODE.test(hint)) {
73
+ return false;
74
+ }
75
+ return CODE_HINT.test(hint) || isNumeric(el) && /\bcode\b/.test(hint);
76
+ };
77
+ const signInScope = (scope) => {
78
+ if (!(scope instanceof Element)) {
79
+ return false;
80
+ }
81
+ const buttons = scope.querySelectorAll(
82
+ "button, input[type=submit], input[type=button], [role=button]"
83
+ );
84
+ return Array.from(buttons).some(
85
+ (button) => SIGN_IN.test(
86
+ words(button instanceof HTMLInputElement ? button.value : button.textContent ?? "")
87
+ )
88
+ );
89
+ };
90
+ const candidates = [];
91
+ for (const inputs of inputsIn(document)) {
92
+ const taken = /* @__PURE__ */ new Set();
93
+ for (let start = 0; start < inputs.length; start++) {
94
+ let end = start;
95
+ while (end < inputs.length && inputs[end].maxLength === 1) {
96
+ end++;
97
+ }
98
+ if (end - start >= 4) {
99
+ const boxes = inputs.slice(start, end);
100
+ for (const box of boxes) {
101
+ taken.add(box);
102
+ }
103
+ candidates.push({ el: boxes[0], kind: "one-time-code", boxes, signIn: false });
104
+ }
105
+ start = Math.max(start, end - 1);
106
+ }
107
+ const passwordsByScope = /* @__PURE__ */ new Map();
108
+ for (const el of inputs) {
109
+ if (el.type === "password") {
110
+ const scope = scopeOf(el);
111
+ passwordsByScope.set(scope, [...passwordsByScope.get(scope) ?? [], el]);
112
+ }
113
+ }
114
+ for (const el of inputs) {
115
+ if (taken.has(el)) {
116
+ continue;
117
+ }
118
+ const scope = scopeOf(el);
119
+ const passwords = passwordsByScope.get(scope) ?? [];
120
+ if (el.type === "password") {
121
+ const signIn = passwords.length === 1 && signInScope(scope);
122
+ const choosing = passwords.length > 1 || !signIn && (autocompleteOf(el) ?? "").includes("new-password");
123
+ candidates.push({ el, kind: choosing ? "new-password" : "password", boxes: [el], signIn });
124
+ } else if (isCodeField(el)) {
125
+ candidates.push({ el, kind: "one-time-code", boxes: [el], signIn: false });
126
+ } else if (passwords.length > 0 && USERNAME_TYPES.has(el.type)) {
127
+ const autocomplete = autocompleteOf(el) ?? "";
128
+ if (el.type === "email" || /\b(username|email|tel)\b/.test(autocomplete) || USERNAME_HINT.test(hintOf(el))) {
129
+ candidates.push({ el, kind: "username", boxes: [el], signIn: false });
130
+ }
131
+ }
132
+ }
133
+ }
134
+ const setValue = (el, value) => {
135
+ const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set;
136
+ if (setter) {
137
+ setter.call(el, value);
138
+ } else {
139
+ el.value = value;
140
+ }
141
+ el.dispatchEvent(new Event("input", { bubbles: true }));
142
+ };
143
+ const pasteEvent = (text) => {
144
+ const init = { bubbles: true, cancelable: true, composed: true };
145
+ try {
146
+ const data = new DataTransfer();
147
+ data.setData("text/plain", text);
148
+ const event2 = new ClipboardEvent("paste", { ...init, clipboardData: data });
149
+ if (event2.clipboardData?.getData("text/plain") === text) {
150
+ return event2;
151
+ }
152
+ } catch {
153
+ }
154
+ const event = new Event("paste", init);
155
+ const clipboardData = { getData: () => text, types: ["text/plain"], items: [], files: [] };
156
+ Object.defineProperty(event, "clipboardData", { value: clipboardData });
157
+ return event;
158
+ };
159
+ const DIGITS = "1234567890123456";
160
+ const expectedLength = (candidate) => {
161
+ const { el, boxes } = candidate;
162
+ if (boxes.length > 1) {
163
+ return boxes.length;
164
+ }
165
+ if (el.maxLength > 0) {
166
+ return el.maxLength;
167
+ }
168
+ const quantifier = /\{(\d+)(?:,\d*)?\}/.exec(el.getAttribute("pattern") ?? "");
169
+ const said = /\b(\d+) digit\b/.exec(hintOf(el));
170
+ const length = Number(quantifier?.[1] ?? said?.[1] ?? 0);
171
+ return length > 0 ? length : null;
172
+ };
173
+ const probeFor = (candidate) => {
174
+ const { el, kind } = candidate;
175
+ const fit = (text) => el.maxLength > 0 ? text.slice(0, el.maxLength) : text;
176
+ if (kind === "one-time-code" || kind !== "username" && isNumeric(el)) {
177
+ const length = expectedLength(candidate) ?? 4;
178
+ return { text: DIGITS.slice(0, Math.max(1, Math.min(length - 1, 16))), partial: true };
179
+ }
180
+ if (kind === "username") {
181
+ return { text: fit(isNumeric(el) ? "5550100" : "probe@example.com"), partial: false };
182
+ }
183
+ return { text: fit("Probe-4f9a-Paste"), partial: false };
184
+ };
185
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
186
+ const waitFor = async (done, ms) => {
187
+ const end = performance.now() + ms;
188
+ while (!done() && performance.now() < end) {
189
+ await sleep(POLL_MS);
190
+ }
191
+ };
192
+ const suppressedLog = [];
193
+ const unhooks = [];
194
+ const hook = (target, key, replacement) => {
195
+ const own = Object.getOwnPropertyDescriptor(target, key);
196
+ try {
197
+ Object.defineProperty(target, key, {
198
+ configurable: true,
199
+ writable: true,
200
+ value: replacement
201
+ });
202
+ } catch {
203
+ return;
204
+ }
205
+ unhooks.push(() => {
206
+ if (target[key] !== replacement) {
207
+ return;
208
+ }
209
+ if (own) {
210
+ Object.defineProperty(target, key, own);
211
+ } else {
212
+ delete target[key];
213
+ }
214
+ });
215
+ };
216
+ const stopSubmit = (event) => {
217
+ suppressedLog.push("submit");
218
+ event.preventDefault();
219
+ event.stopImmediatePropagation();
220
+ };
221
+ const guardedForms = /* @__PURE__ */ new Set();
222
+ const guardForm = (form) => {
223
+ if (form && !guardedForms.has(form)) {
224
+ guardedForms.add(form);
225
+ form.addEventListener("submit", stopSubmit, true);
226
+ }
227
+ };
228
+ const installGuards = () => {
229
+ window.addEventListener("submit", stopSubmit, true);
230
+ unhooks.push(() => {
231
+ window.removeEventListener("submit", stopSubmit, true);
232
+ for (const form of guardedForms) {
233
+ form.removeEventListener("submit", stopSubmit, true);
234
+ }
235
+ });
236
+ const noSubmit = () => {
237
+ suppressedLog.push("submit");
238
+ };
239
+ if (typeof HTMLFormElement !== "undefined") {
240
+ hook(HTMLFormElement.prototype, "submit", noSubmit);
241
+ hook(HTMLFormElement.prototype, "requestSubmit", noSubmit);
242
+ }
243
+ if (typeof window.fetch === "function") {
244
+ hook(window, "fetch", () => {
245
+ suppressedLog.push("request");
246
+ return Promise.reject(new DOMException("Stopped while the page is audited", "AbortError"));
247
+ });
248
+ }
249
+ if (typeof XMLHttpRequest !== "undefined") {
250
+ hook(XMLHttpRequest.prototype, "send", function() {
251
+ suppressedLog.push("request");
252
+ try {
253
+ this.abort();
254
+ } catch {
255
+ }
256
+ setTimeout(() => {
257
+ for (const type of ["error", "loadend"]) {
258
+ this.dispatchEvent(
259
+ typeof ProgressEvent === "function" ? new ProgressEvent(type) : new Event(type)
260
+ );
261
+ }
262
+ }, 0);
263
+ });
264
+ }
265
+ if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
266
+ hook(navigator, "sendBeacon", () => {
267
+ suppressedLog.push("request");
268
+ return true;
269
+ });
270
+ }
271
+ };
272
+ const restore = (boxes, originals) => {
273
+ let restored = false;
274
+ boxes.forEach((box, i) => {
275
+ if (box.value !== originals[i]) {
276
+ setValue(box, originals[i]);
277
+ restored = true;
278
+ }
279
+ });
280
+ return restored;
281
+ };
282
+ const wroteInto = (boxes, originals) => boxes.some((box, i) => box.value !== originals[i] && box.value !== "");
283
+ const attemptPaste = async (candidate, text, originals) => {
284
+ const { el, boxes } = candidate;
285
+ const wrote = () => wroteInto(boxes, originals);
286
+ const init = { bubbles: true, cancelable: true, composed: true };
287
+ const mark = suppressedLog.length;
288
+ const blocked = [];
289
+ let suppressed = [];
290
+ let handled = false;
291
+ const refused = async (event) => {
292
+ if (!event.defaultPrevented) {
293
+ return false;
294
+ }
295
+ await waitFor(wrote, REFUSAL_WAIT_MS);
296
+ if (wrote()) {
297
+ handled = true;
298
+ return false;
299
+ }
300
+ return true;
301
+ };
302
+ try {
303
+ for (const modifier of ["ctrlKey", "metaKey"]) {
304
+ const press = new KeyboardEvent("keydown", {
305
+ ...init,
306
+ key: "v",
307
+ code: "KeyV",
308
+ [modifier]: true
309
+ });
310
+ el.dispatchEvent(press);
311
+ if (await refused(press) && !blocked.includes("shortcut")) {
312
+ blocked.push("shortcut");
313
+ }
314
+ }
315
+ if (!handled) {
316
+ const beforeInput = new InputEvent("beforeinput", {
317
+ ...init,
318
+ inputType: "insertFromPaste",
319
+ data: text
320
+ });
321
+ el.dispatchEvent(beforeInput);
322
+ if (await refused(beforeInput)) {
323
+ blocked.push("beforeinput");
324
+ }
325
+ }
326
+ if (!handled) {
327
+ const paste = pasteEvent(text);
328
+ el.dispatchEvent(paste);
329
+ if (await refused(paste)) {
330
+ blocked.push("paste");
331
+ } else {
332
+ if (boxes.length > 1 && !paste.defaultPrevented) {
333
+ await waitFor(wrote, REFUSAL_WAIT_MS);
334
+ }
335
+ if (wrote()) {
336
+ handled = true;
337
+ }
338
+ }
339
+ }
340
+ } finally {
341
+ suppressed = Array.from(new Set(suppressedLog.slice(mark)));
342
+ restore(boxes, originals);
343
+ }
344
+ return handled ? { blocked: [], handled, suppressed } : { blocked, handled, suppressed };
345
+ };
346
+ const withFocus = async (el, run) => {
347
+ const root = el.getRootNode();
348
+ const wasFocused = root.activeElement === el;
349
+ if (!wasFocused) {
350
+ el.focus({ preventScroll: true });
351
+ if (root.activeElement !== el) {
352
+ el.dispatchEvent(new FocusEvent("focus"));
353
+ el.dispatchEvent(new FocusEvent("focusin", { bubbles: true, composed: true }));
354
+ }
355
+ }
356
+ try {
357
+ return await run();
358
+ } finally {
359
+ if (!wasFocused) {
360
+ el.blur();
361
+ }
362
+ }
363
+ };
364
+ const focusedElement = () => {
365
+ let active = document.activeElement;
366
+ while (active?.shadowRoot?.activeElement) {
367
+ active = active.shadowRoot.activeElement;
368
+ }
369
+ return active;
370
+ };
371
+ const focusedBefore = focusedElement();
372
+ let selectionBefore = null;
373
+ if (focusedBefore instanceof HTMLInputElement || focusedBefore instanceof HTMLTextAreaElement) {
374
+ try {
375
+ const { selectionStart, selectionEnd, selectionDirection } = focusedBefore;
376
+ if (selectionStart !== null && selectionEnd !== null) {
377
+ selectionBefore = [selectionStart, selectionEnd, selectionDirection ?? "none"];
378
+ }
379
+ } catch {
380
+ }
381
+ }
382
+ const restoreFocus = () => {
383
+ const now = focusedElement();
384
+ if (now !== focusedBefore) {
385
+ if (focusedBefore instanceof HTMLElement && focusedBefore !== document.body && focusedBefore.isConnected) {
386
+ focusedBefore.focus({ preventScroll: true });
387
+ } else if (now instanceof HTMLElement) {
388
+ now.blur();
389
+ }
390
+ }
391
+ if (selectionBefore && (focusedBefore instanceof HTMLInputElement || focusedBefore instanceof HTMLTextAreaElement)) {
392
+ try {
393
+ focusedBefore.setSelectionRange(...selectionBefore);
394
+ } catch {
395
+ }
396
+ }
397
+ };
398
+ const elements = [];
399
+ const fields = [];
400
+ const probed = [];
401
+ installGuards();
402
+ try {
403
+ for (const candidate of candidates.slice(0, fieldLimit)) {
404
+ const { el, boxes } = candidate;
405
+ const probe = probeFor(candidate);
406
+ const originals = boxes.map((box) => box.value);
407
+ const startedReadOnly = el.readOnly;
408
+ const suppressed = /* @__PURE__ */ new Set();
409
+ let readonlyUntilFocus = false;
410
+ let attempt = { blocked: [], handled: false, suppressed: [] };
411
+ const paste = async () => {
412
+ const result = await attemptPaste(candidate, probe.text, originals);
413
+ for (const action of result.suppressed) {
414
+ suppressed.add(action);
415
+ }
416
+ return result;
417
+ };
418
+ guardForm(el.form);
419
+ if (startedReadOnly) {
420
+ attempt = await withFocus(el, async () => {
421
+ readonlyUntilFocus = !el.readOnly;
422
+ return el.readOnly ? attempt : paste();
423
+ });
424
+ el.readOnly = true;
425
+ } else {
426
+ attempt = await paste();
427
+ if (attempt.blocked.length > 0) {
428
+ attempt = await withFocus(el, paste);
429
+ }
430
+ }
431
+ const field = {
432
+ kind: candidate.kind,
433
+ html: el.cloneNode(false).outerHTML,
434
+ autocomplete: autocompleteOf(el),
435
+ blocked: attempt.blocked,
436
+ inlineHandler: el.closest("[onpaste]") !== null,
437
+ handled: attempt.handled,
438
+ readonlyUntilFocus,
439
+ boxes: boxes.length > 1 ? boxes.length : 0,
440
+ signIn: candidate.signIn,
441
+ partialProbe: probe.partial,
442
+ suppressed: Array.from(suppressed)
443
+ };
444
+ elements.push(el);
445
+ fields.push(field);
446
+ probed.push({ boxes, originals, field });
447
+ }
448
+ if (probed.length > 0) {
449
+ await sleep(FINAL_SETTLE_MS);
450
+ for (let round = 0; round < 2; round++) {
451
+ let restored = false;
452
+ for (const { boxes, originals, field } of probed) {
453
+ if (wroteInto(boxes, originals)) {
454
+ field.handled = true;
455
+ field.blocked = [];
456
+ }
457
+ restored = restore(boxes, originals) || restored;
458
+ }
459
+ if (!restored) {
460
+ break;
461
+ }
462
+ await sleep(RECHECK_MS);
463
+ }
464
+ }
465
+ } finally {
466
+ for (const { boxes, originals } of probed) {
467
+ restore(boxes, originals);
468
+ }
469
+ for (const unhook of unhooks.reverse()) {
470
+ unhook();
471
+ }
472
+ restoreFocus();
473
+ }
474
+ window[stashKey] = elements;
475
+ return { fields, total: candidates.length };
476
+ }
477
+
478
+ // src/classify.ts
479
+ function classifyField(field) {
480
+ const signals = [];
481
+ const tokens = (field.autocomplete ?? "").split(/\s+/);
482
+ if (field.blocked.includes("paste")) {
483
+ signals.push(field.partialProbe ? "partial-paste-refused" : "paste-blocked");
484
+ } else if (field.blocked.length > 0) {
485
+ signals.push("paste-may-be-blocked");
486
+ } else if (field.boxes > 0 && !field.handled && !field.readonlyUntilFocus) {
487
+ signals.push("split-code-paste-unhandled");
488
+ }
489
+ if (field.readonlyUntilFocus) {
490
+ signals.push("readonly-until-focus");
491
+ }
492
+ if (tokens.includes("off")) {
493
+ signals.push("autocomplete-off");
494
+ }
495
+ if (field.kind === "password" && field.signIn && tokens.includes("new-password")) {
496
+ signals.push("new-password-on-sign-in");
497
+ }
498
+ if (field.kind === "one-time-code" && field.boxes === 0 && !tokens.includes("one-time-code") && !tokens.includes("off")) {
499
+ signals.push("no-autofill-hint");
500
+ }
501
+ if (signals.length === 0) {
502
+ return { signals, verdict: null };
503
+ }
504
+ return { signals, verdict: signals[0] === "paste-blocked" ? "failed" : "review" };
505
+ }
506
+
507
+ // src/audit.ts
508
+ var DEFAULT_FIELD_LIMIT = 50;
509
+ var DEFAULT_REPORT_LIMIT = 10;
510
+ var STASH_KEY = "__a11yPulsePasteBlocking";
511
+ async function toFields(adaptor, classified) {
512
+ const selectors = await stashedElementSelectors(
513
+ adaptor,
514
+ STASH_KEY,
515
+ classified.map(({ index }) => index)
516
+ );
517
+ return classified.map(({ field, classification }, i) => {
518
+ const refused = field.blocked.length > 0;
519
+ return {
520
+ selector: selectors[i],
521
+ html: truncateHtml(field.html),
522
+ kind: field.kind,
523
+ signals: classification.signals,
524
+ blocked: field.blocked,
525
+ detectedBy: refused ? field.inlineHandler ? "inline-handler" : "event-listener" : null,
526
+ autocomplete: field.autocomplete,
527
+ boxes: field.boxes > 0 ? field.boxes : null,
528
+ partialProbe: field.partialProbe,
529
+ suppressed: field.suppressed
530
+ };
531
+ });
532
+ }
533
+ async function runPasteBlockingAudit(adaptor, options = {}) {
534
+ const fieldLimit = options.fieldLimit ?? DEFAULT_FIELD_LIMIT;
535
+ const reportLimit = options.reportLimit ?? DEFAULT_REPORT_LIMIT;
536
+ await adaptor.ensureFocusReporting();
537
+ const inspection = await adaptor.evaluate(inspectAuthFieldsScript, STASH_KEY, fieldLimit);
538
+ try {
539
+ const classified = inspection.fields.map((field, index) => ({
540
+ index,
541
+ field,
542
+ classification: classifyField(field)
543
+ }));
544
+ const failed = classified.filter(({ classification }) => classification.verdict === "failed");
545
+ const needsReview = classified.filter(
546
+ ({ classification }) => classification.verdict === "review"
547
+ );
548
+ const passed = classified.filter(({ classification }) => classification.verdict === null);
549
+ return {
550
+ failed: await toFields(adaptor, failed.slice(0, reportLimit)),
551
+ needsReview: await toFields(adaptor, needsReview.slice(0, reportLimit)),
552
+ passed: await toFields(adaptor, passed.slice(0, reportLimit)),
553
+ summary: {
554
+ checked: classified.length,
555
+ failed: failed.length,
556
+ needsReview: needsReview.length,
557
+ passed: passed.length,
558
+ unchecked: inspection.total - classified.length
559
+ }
560
+ };
561
+ } finally {
562
+ await releaseStashedElements(adaptor, STASH_KEY);
563
+ }
564
+ }
565
+ export {
566
+ DEFAULT_FIELD_LIMIT,
567
+ DEFAULT_REPORT_LIMIT,
568
+ classifyField,
569
+ runPasteBlockingAudit
570
+ };
571
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/audit.ts","../src/browser-scripts.ts","../src/classify.ts"],"sourcesContent":["import {\n\ttype BrowserAdaptor,\n\treleaseStashedElements,\n\tstashedElementSelectors,\n} from \"@a11y-pulse/browser-adaptor\";\nimport { truncateHtml } from \"@a11y-pulse/browser-adaptor/dom\";\nimport { type InspectedField, inspectAuthFieldsScript } from \"./browser-scripts\";\nimport { classifyField, type FieldClassification } from \"./classify\";\nimport type { PasteBlockingField, PasteBlockingResult } from \"./result\";\n\nexport const DEFAULT_FIELD_LIMIT = 50;\nexport const DEFAULT_REPORT_LIMIT = 10;\n\nconst STASH_KEY = \"__a11yPulsePasteBlocking\";\n\nexport type PasteBlockingOptions = {\n\t/** Max authentication fields to inspect. Defaults to 50. */\n\tfieldLimit?: number;\n\t/** Max fields to report in each of `failed`, `needsReview` and `passed`. Defaults to 10. */\n\treportLimit?: number;\n};\n\ntype Classified = { index: number; field: InspectedField; classification: FieldClassification };\n\nasync function toFields(\n\tadaptor: BrowserAdaptor,\n\tclassified: readonly Classified[],\n): Promise<PasteBlockingField[]> {\n\tconst selectors = await stashedElementSelectors(\n\t\tadaptor,\n\t\tSTASH_KEY,\n\t\tclassified.map(({ index }) => index),\n\t);\n\n\treturn classified.map(({ field, classification }, i) => {\n\t\tconst refused = field.blocked.length > 0;\n\n\t\treturn {\n\t\t\tselector: selectors[i]!,\n\t\t\thtml: truncateHtml(field.html),\n\t\t\tkind: field.kind,\n\t\t\tsignals: classification.signals,\n\t\t\tblocked: field.blocked,\n\t\t\tdetectedBy: refused ? (field.inlineHandler ? \"inline-handler\" : \"event-listener\") : null,\n\t\t\tautocomplete: field.autocomplete,\n\t\t\tboxes: field.boxes > 0 ? field.boxes : null,\n\t\t\tpartialProbe: field.partialProbe,\n\t\t\tsuppressed: field.suppressed,\n\t\t};\n\t});\n}\n\n/**\n * Find the page's password, username and one-time-code fields and check that nothing stops a\n * password manager or a paste from filling them. Pastes are simulated with synthetic events and\n * the clipboard is not touched. So that the page cannot act on the pasted text, a one-time code is\n * pasted a digit short, and form submission and `fetch`, `XMLHttpRequest` and `sendBeacon` requests\n * are stopped until every field value and the focus are back as they were found.\n */\nexport async function runPasteBlockingAudit(\n\tadaptor: BrowserAdaptor,\n\toptions: PasteBlockingOptions = {},\n): Promise<PasteBlockingResult> {\n\tconst fieldLimit = options.fieldLimit ?? DEFAULT_FIELD_LIMIT;\n\tconst reportLimit = options.reportLimit ?? DEFAULT_REPORT_LIMIT;\n\n\t// Focusing a field to see whether it unlocks only fires its handlers on a page that has focus.\n\tawait adaptor.ensureFocusReporting();\n\n\tconst inspection = await adaptor.evaluate(inspectAuthFieldsScript, STASH_KEY, fieldLimit);\n\n\ttry {\n\t\tconst classified: Classified[] = inspection.fields.map((field, index) => ({\n\t\t\tindex,\n\t\t\tfield,\n\t\t\tclassification: classifyField(field),\n\t\t}));\n\n\t\tconst failed = classified.filter(({ classification }) => classification.verdict === \"failed\");\n\t\tconst needsReview = classified.filter(\n\t\t\t({ classification }) => classification.verdict === \"review\",\n\t\t);\n\t\tconst passed = classified.filter(({ classification }) => classification.verdict === null);\n\n\t\treturn {\n\t\t\tfailed: await toFields(adaptor, failed.slice(0, reportLimit)),\n\t\t\tneedsReview: await toFields(adaptor, needsReview.slice(0, reportLimit)),\n\t\t\tpassed: await toFields(adaptor, passed.slice(0, reportLimit)),\n\t\t\tsummary: {\n\t\t\t\tchecked: classified.length,\n\t\t\t\tfailed: failed.length,\n\t\t\t\tneedsReview: needsReview.length,\n\t\t\t\tpassed: passed.length,\n\t\t\t\tunchecked: inspection.total - classified.length,\n\t\t\t},\n\t\t};\n\t} finally {\n\t\tawait releaseStashedElements(adaptor, STASH_KEY);\n\t}\n}\n","/**\n * IMPORTANT: Functions in this file are serialized and injected into the audited page, so they must\n * not reference any symbols outside their own scope.\n */\n\n/** What an authentication field takes. `new-password` is a password being chosen or confirmed. */\nexport type AuthFieldKind = \"password\" | \"new-password\" | \"username\" | \"one-time-code\";\n\n/**\n * A way the page refused a paste: it cancelled the `paste` event, cancelled the `beforeinput`\n * event for a paste, or cancelled the Ctrl+V or Cmd+V key press.\n */\nexport type BlockMechanism = \"paste\" | \"beforeinput\" | \"shortcut\";\n\n/**\n * Something the page tried to do while a field was being pasted into: submit a form (`submit`), or\n * send a request with `fetch`, `XMLHttpRequest` or `navigator.sendBeacon` (`request`).\n */\nexport type SuppressedAction = \"submit\" | \"request\";\n\nexport type InspectedField = {\n\tkind: AuthFieldKind;\n\t/** Shallow outerHTML. */\n\thtml: string;\n\t/** The field's own `autocomplete`, lower-cased, or its form's when it has none. Null if unset. */\n\tautocomplete: string | null;\n\t/** Every way the page refused the paste, with the field left unchanged. */\n\tblocked: BlockMechanism[];\n\t/** An `onpaste` attribute on the field or an ancestor, as opposed to a script's listener. */\n\tinlineHandler: boolean;\n\t/** The page put the pasted text into the field itself. */\n\thandled: boolean;\n\t/** The field was `readonly` until it was focused. */\n\treadonlyUntilFocus: boolean;\n\t/** How many single-character boxes the field is split into, or 0 for an ordinary field. */\n\tboxes: number;\n\t/** A lone password field in a form whose submit button says \"sign in\" or \"log in\". */\n\tsignIn: boolean;\n\t/**\n\t * The pasted text was a digit short of what the field takes, as it is for a one-time code or a\n\t * numeric PIN, so that the page cannot take it for a complete value and send it.\n\t */\n\tpartialProbe: boolean;\n\t/** What the page tried to do in response to the paste, and was stopped from doing. */\n\tsuppressed: SuppressedAction[];\n};\n\nexport type AuthFieldInspection = {\n\tfields: InspectedField[];\n\t/** Every authentication field, including those past the limit. */\n\ttotal: number;\n};\n\n/**\n * Find every rendered password, username and one-time-code field, descending open shadow roots,\n * and paste into each with synthetic events to see whether the page refuses. Any value the page\n * writes in response is put back, including one written a moment later, and focus is returned to\n * where it was. While the fields are pasted into, form submission and requests made with `fetch`,\n * `XMLHttpRequest` and `sendBeacon` are stopped, and a one-time code is pasted a digit short, so\n * the page cannot send the pasted text anywhere. The inspected elements are left on\n * `window[stashKey]`, in the same order.\n */\nexport async function inspectAuthFieldsScript(\n\tstashKey: string,\n\tfieldLimit: number,\n): Promise<AuthFieldInspection> {\n\tconst TEXT_TYPES = new Set([\"text\", \"tel\", \"number\", \"email\", \"password\", \"search\", \"url\"]);\n\tconst USERNAME_TYPES = new Set([\"text\", \"email\", \"tel\"]);\n\n\tconst CODE_HINT =\n\t\t/\\b(otp|totp|2fa|mfa|one time|verification code|verify code|auth code|authentication code|passcode|pass code|sms code|\\d+ digit code)\\b/;\n\tconst NOT_A_SIGN_IN_CODE =\n\t\t/\\b(post|postal|postcode|zip|promo|coupon|discount|voucher|gift|country|area|referral|invite|card|cvv|cvc|product|sku|tracking|order|dial)\\b/;\n\tconst USERNAME_HINT = /\\b(user|username|email|e mail|login|account|phone|mobile)\\b/;\n\tconst SIGN_IN = /\\b(sign in|log in|login|signin)\\b/;\n\n\t// How long a cancelled paste is given for the page to write the text in itself.\n\tconst REFUSAL_WAIT_MS = 150;\n\tconst POLL_MS = 25;\n\t// How long after the last paste the fields are looked at again for a value written late.\n\tconst FINAL_SETTLE_MS = 300;\n\tconst RECHECK_MS = 100;\n\n\tconst isRendered = (el: Element): boolean =>\n\t\ttypeof el.checkVisibility === \"function\"\n\t\t\t? el.checkVisibility({ visibilityProperty: true })\n\t\t\t: el.getClientRects().length > 0;\n\n\tconst words = (text: string): string =>\n\t\ttext\n\t\t\t.toLowerCase()\n\t\t\t.replace(/[^a-z0-9]+/g, \" \")\n\t\t\t.trim();\n\n\tconst inputsIn = (root: Document | ShadowRoot): HTMLInputElement[][] => {\n\t\tconst groups: HTMLInputElement[][] = [];\n\t\tconst own: HTMLInputElement[] = [];\n\n\t\tfor (const el of root.querySelectorAll(\"*\")) {\n\t\t\tif (el instanceof HTMLInputElement) {\n\t\t\t\tconst type = el.type.toLowerCase();\n\n\t\t\t\tif (TEXT_TYPES.has(type) && !el.disabled && isRendered(el)) {\n\t\t\t\t\town.push(el);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (el.shadowRoot) {\n\t\t\t\tgroups.push(...inputsIn(el.shadowRoot));\n\t\t\t}\n\t\t}\n\n\t\treturn [own, ...groups];\n\t};\n\n\tconst scopeOf = (el: HTMLInputElement): Node =>\n\t\tel.form ??\n\t\tel.closest(\"[role=form], fieldset, dialog, [role=dialog], section, main\") ??\n\t\tel.getRootNode();\n\n\tconst autocompleteOf = (el: HTMLInputElement): string | null => {\n\t\tconst own = el.getAttribute(\"autocomplete\")?.trim().toLowerCase();\n\n\t\tif (own) {\n\t\t\treturn own;\n\t\t}\n\n\t\treturn el.form?.getAttribute(\"autocomplete\")?.trim().toLowerCase() || null;\n\t};\n\n\tconst hintOf = (el: HTMLInputElement): string => {\n\t\tconst labels = Array.from(el.labels ?? [], (label) => label.textContent ?? \"\");\n\n\t\treturn words(\n\t\t\t[\n\t\t\t\tel.name,\n\t\t\t\tel.id,\n\t\t\t\tel.getAttribute(\"placeholder\"),\n\t\t\t\tel.getAttribute(\"aria-label\"),\n\t\t\t\tel.getAttribute(\"title\"),\n\t\t\t\t...labels,\n\t\t\t].join(\" \"),\n\t\t);\n\t};\n\n\tconst isNumeric = (el: HTMLInputElement): boolean => {\n\t\tconst pattern = el.getAttribute(\"pattern\") ?? \"\";\n\n\t\treturn (\n\t\t\tel.getAttribute(\"inputmode\")?.toLowerCase() === \"numeric\" ||\n\t\t\tel.type === \"number\" ||\n\t\t\tel.type === \"tel\" ||\n\t\t\tpattern.includes(\"\\\\d\") ||\n\t\t\tpattern.includes(\"0-9\")\n\t\t);\n\t};\n\n\tconst isCodeField = (el: HTMLInputElement): boolean => {\n\t\tconst autocomplete = autocompleteOf(el) ?? \"\";\n\n\t\tif (autocomplete.split(/\\s+/).includes(\"one-time-code\")) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (el.type === \"password\" || el.type === \"email\" || autocomplete.startsWith(\"cc-\")) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst hint = hintOf(el);\n\n\t\tif (NOT_A_SIGN_IN_CODE.test(hint)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn CODE_HINT.test(hint) || (isNumeric(el) && /\\bcode\\b/.test(hint));\n\t};\n\n\tconst signInScope = (scope: Node): boolean => {\n\t\tif (!(scope instanceof Element)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst buttons = scope.querySelectorAll(\n\t\t\t\"button, input[type=submit], input[type=button], [role=button]\",\n\t\t);\n\n\t\treturn Array.from(buttons).some((button) =>\n\t\t\tSIGN_IN.test(\n\t\t\t\twords(button instanceof HTMLInputElement ? button.value : (button.textContent ?? \"\")),\n\t\t\t),\n\t\t);\n\t};\n\n\ttype Candidate = {\n\t\tel: HTMLInputElement;\n\t\tkind: AuthFieldKind;\n\t\tboxes: HTMLInputElement[];\n\t\tsignIn: boolean;\n\t};\n\n\tconst candidates: Candidate[] = [];\n\n\tfor (const inputs of inputsIn(document)) {\n\t\tconst taken = new Set<HTMLInputElement>();\n\n\t\t// A run of four or more single-character boxes is a split code entry, reported at its first box.\n\t\tfor (let start = 0; start < inputs.length; start++) {\n\t\t\tlet end = start;\n\n\t\t\twhile (end < inputs.length && inputs[end]!.maxLength === 1) {\n\t\t\t\tend++;\n\t\t\t}\n\n\t\t\tif (end - start >= 4) {\n\t\t\t\tconst boxes = inputs.slice(start, end);\n\n\t\t\t\tfor (const box of boxes) {\n\t\t\t\t\ttaken.add(box);\n\t\t\t\t}\n\n\t\t\t\tcandidates.push({ el: boxes[0]!, kind: \"one-time-code\", boxes, signIn: false });\n\t\t\t}\n\n\t\t\tstart = Math.max(start, end - 1);\n\t\t}\n\n\t\tconst passwordsByScope = new Map<Node, HTMLInputElement[]>();\n\n\t\tfor (const el of inputs) {\n\t\t\tif (el.type === \"password\") {\n\t\t\t\tconst scope = scopeOf(el);\n\t\t\t\tpasswordsByScope.set(scope, [...(passwordsByScope.get(scope) ?? []), el]);\n\t\t\t}\n\t\t}\n\n\t\tfor (const el of inputs) {\n\t\t\tif (taken.has(el)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst scope = scopeOf(el);\n\t\t\tconst passwords = passwordsByScope.get(scope) ?? [];\n\n\t\t\tif (el.type === \"password\") {\n\t\t\t\tconst signIn = passwords.length === 1 && signInScope(scope);\n\t\t\t\tconst choosing =\n\t\t\t\t\tpasswords.length > 1 || (!signIn && (autocompleteOf(el) ?? \"\").includes(\"new-password\"));\n\n\t\t\t\tcandidates.push({ el, kind: choosing ? \"new-password\" : \"password\", boxes: [el], signIn });\n\t\t\t} else if (isCodeField(el)) {\n\t\t\t\tcandidates.push({ el, kind: \"one-time-code\", boxes: [el], signIn: false });\n\t\t\t} else if (passwords.length > 0 && USERNAME_TYPES.has(el.type)) {\n\t\t\t\tconst autocomplete = autocompleteOf(el) ?? \"\";\n\n\t\t\t\tif (\n\t\t\t\t\tel.type === \"email\" ||\n\t\t\t\t\t/\\b(username|email|tel)\\b/.test(autocomplete) ||\n\t\t\t\t\tUSERNAME_HINT.test(hintOf(el))\n\t\t\t\t) {\n\t\t\t\t\tcandidates.push({ el, kind: \"username\", boxes: [el], signIn: false });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst setValue = (el: HTMLInputElement, value: string): void => {\n\t\tconst setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, \"value\")?.set;\n\n\t\tif (setter) {\n\t\t\tsetter.call(el, value);\n\t\t} else {\n\t\t\tel.value = value;\n\t\t}\n\n\t\tel.dispatchEvent(new Event(\"input\", { bubbles: true }));\n\t};\n\n\tconst pasteEvent = (text: string): Event => {\n\t\tconst init = { bubbles: true, cancelable: true, composed: true };\n\n\t\ttry {\n\t\t\tconst data = new DataTransfer();\n\t\t\tdata.setData(\"text/plain\", text);\n\n\t\t\tconst event = new ClipboardEvent(\"paste\", { ...init, clipboardData: data });\n\n\t\t\tif (event.clipboardData?.getData(\"text/plain\") === text) {\n\t\t\t\treturn event;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to a plain event carrying the text.\n\t\t}\n\n\t\tconst event = new Event(\"paste\", init);\n\t\tconst clipboardData = { getData: () => text, types: [\"text/plain\"], items: [], files: [] };\n\t\tObject.defineProperty(event, \"clipboardData\", { value: clipboardData });\n\n\t\treturn event;\n\t};\n\n\tconst DIGITS = \"1234567890123456\";\n\n\t/** How many characters the field expects, when its markup says. */\n\tconst expectedLength = (candidate: Candidate): number | null => {\n\t\tconst { el, boxes } = candidate;\n\n\t\tif (boxes.length > 1) {\n\t\t\treturn boxes.length;\n\t\t}\n\n\t\tif (el.maxLength > 0) {\n\t\t\treturn el.maxLength;\n\t\t}\n\n\t\tconst quantifier = /\\{(\\d+)(?:,\\d*)?\\}/.exec(el.getAttribute(\"pattern\") ?? \"\");\n\t\tconst said = /\\b(\\d+) digit\\b/.exec(hintOf(el));\n\t\tconst length = Number(quantifier?.[1] ?? said?.[1] ?? 0);\n\n\t\treturn length > 0 ? length : null;\n\t};\n\n\ttype Probe = { text: string; partial: boolean };\n\n\t/**\n\t * The text to paste, shaped to what the field takes so that it is not turned away for being the\n\t * wrong kind. A one-time code or numeric PIN is pasted a digit short of its length, or three\n\t * digits when the length is unknown, so the page never holds a complete code it could send.\n\t */\n\tconst probeFor = (candidate: Candidate): Probe => {\n\t\tconst { el, kind } = candidate;\n\t\tconst fit = (text: string): string => (el.maxLength > 0 ? text.slice(0, el.maxLength) : text);\n\n\t\tif (kind === \"one-time-code\" || (kind !== \"username\" && isNumeric(el))) {\n\t\t\tconst length = expectedLength(candidate) ?? 4;\n\n\t\t\treturn { text: DIGITS.slice(0, Math.max(1, Math.min(length - 1, 16))), partial: true };\n\t\t}\n\n\t\tif (kind === \"username\") {\n\t\t\treturn { text: fit(isNumeric(el) ? \"5550100\" : \"probe@example.com\"), partial: false };\n\t\t}\n\n\t\treturn { text: fit(\"Probe-4f9a-Paste\"), partial: false };\n\t};\n\n\tconst sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));\n\n\tconst waitFor = async (done: () => boolean, ms: number): Promise<void> => {\n\t\tconst end = performance.now() + ms;\n\n\t\twhile (!done() && performance.now() < end) {\n\t\t\tawait sleep(POLL_MS);\n\t\t}\n\t};\n\n\tconst suppressedLog: SuppressedAction[] = [];\n\tconst unhooks: (() => void)[] = [];\n\n\t/** Replace a method until the inspection ends, unless the page has swapped it again by then. */\n\tconst hook = (target: object, key: string, replacement: unknown): void => {\n\t\tconst own = Object.getOwnPropertyDescriptor(target, key);\n\n\t\ttry {\n\t\t\tObject.defineProperty(target, key, {\n\t\t\t\tconfigurable: true,\n\t\t\t\twritable: true,\n\t\t\t\tvalue: replacement,\n\t\t\t});\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\n\t\tunhooks.push(() => {\n\t\t\tif ((target as Record<string, unknown>)[key] !== replacement) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (own) {\n\t\t\t\tObject.defineProperty(target, key, own);\n\t\t\t} else {\n\t\t\t\tdelete (target as Record<string, unknown>)[key];\n\t\t\t}\n\t\t});\n\t};\n\n\tconst stopSubmit = (event: Event): void => {\n\t\tsuppressedLog.push(\"submit\");\n\t\tevent.preventDefault();\n\t\tevent.stopImmediatePropagation();\n\t};\n\n\tconst guardedForms = new Set<HTMLFormElement>();\n\n\t/** `submit` does not cross a shadow root, so a form inside one is guarded directly. */\n\tconst guardForm = (form: HTMLFormElement | null): void => {\n\t\tif (form && !guardedForms.has(form)) {\n\t\t\tguardedForms.add(form);\n\t\t\tform.addEventListener(\"submit\", stopSubmit, true);\n\t\t}\n\t};\n\n\t/**\n\t * Keep the page from sending anything while its fields are pasted into: a handler that submits\n\t * or verifies as soon as a field looks complete would otherwise act on the pasted text.\n\t */\n\tconst installGuards = (): void => {\n\t\twindow.addEventListener(\"submit\", stopSubmit, true);\n\t\tunhooks.push(() => {\n\t\t\twindow.removeEventListener(\"submit\", stopSubmit, true);\n\n\t\t\tfor (const form of guardedForms) {\n\t\t\t\tform.removeEventListener(\"submit\", stopSubmit, true);\n\t\t\t}\n\t\t});\n\n\t\tconst noSubmit = (): void => {\n\t\t\tsuppressedLog.push(\"submit\");\n\t\t};\n\n\t\tif (typeof HTMLFormElement !== \"undefined\") {\n\t\t\thook(HTMLFormElement.prototype, \"submit\", noSubmit);\n\t\t\thook(HTMLFormElement.prototype, \"requestSubmit\", noSubmit);\n\t\t}\n\n\t\tif (typeof window.fetch === \"function\") {\n\t\t\thook(window, \"fetch\", () => {\n\t\t\t\tsuppressedLog.push(\"request\");\n\n\t\t\t\treturn Promise.reject(new DOMException(\"Stopped while the page is audited\", \"AbortError\"));\n\t\t\t});\n\t\t}\n\n\t\tif (typeof XMLHttpRequest !== \"undefined\") {\n\t\t\thook(XMLHttpRequest.prototype, \"send\", function (this: XMLHttpRequest) {\n\t\t\t\tsuppressedLog.push(\"request\");\n\n\t\t\t\ttry {\n\t\t\t\t\tthis.abort();\n\t\t\t\t} catch {\n\t\t\t\t\t// Not opened: there is nothing to abort.\n\t\t\t\t}\n\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tfor (const type of [\"error\", \"loadend\"]) {\n\t\t\t\t\t\tthis.dispatchEvent(\n\t\t\t\t\t\t\ttypeof ProgressEvent === \"function\" ? new ProgressEvent(type) : new Event(type),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}, 0);\n\t\t\t});\n\t\t}\n\n\t\tif (typeof navigator !== \"undefined\" && typeof navigator.sendBeacon === \"function\") {\n\t\t\t// Reported as queued, so the page does not fall back to another way of sending.\n\t\t\thook(navigator, \"sendBeacon\", () => {\n\t\t\t\tsuppressedLog.push(\"request\");\n\n\t\t\t\treturn true;\n\t\t\t});\n\t\t}\n\t};\n\n\ttype Attempt = { blocked: BlockMechanism[]; handled: boolean; suppressed: SuppressedAction[] };\n\n\tconst restore = (boxes: readonly HTMLInputElement[], originals: readonly string[]): boolean => {\n\t\tlet restored = false;\n\n\t\tboxes.forEach((box, i) => {\n\t\t\tif (box.value !== originals[i]) {\n\t\t\t\tsetValue(box, originals[i]!);\n\t\t\t\trestored = true;\n\t\t\t}\n\t\t});\n\n\t\treturn restored;\n\t};\n\n\t/** The page has put text of its own choosing into the field, as opposed to emptying it. */\n\tconst wroteInto = (boxes: readonly HTMLInputElement[], originals: readonly string[]): boolean =>\n\t\tboxes.some((box, i) => box.value !== originals[i] && box.value !== \"\");\n\n\tconst attemptPaste = async (\n\t\tcandidate: Candidate,\n\t\ttext: string,\n\t\toriginals: readonly string[],\n\t): Promise<Attempt> => {\n\t\tconst { el, boxes } = candidate;\n\t\tconst wrote = (): boolean => wroteInto(boxes, originals);\n\t\tconst init = { bubbles: true, cancelable: true, composed: true };\n\t\tconst mark = suppressedLog.length;\n\n\t\tconst blocked: BlockMechanism[] = [];\n\t\tlet suppressed: SuppressedAction[] = [];\n\t\tlet handled = false;\n\n\t\t// A refusal only counts once the page has had a moment to write the text in itself.\n\t\tconst refused = async (event: Event): Promise<boolean> => {\n\t\t\tif (!event.defaultPrevented) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tawait waitFor(wrote, REFUSAL_WAIT_MS);\n\n\t\t\tif (wrote()) {\n\t\t\t\thandled = true;\n\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t};\n\n\t\ttry {\n\t\t\tfor (const modifier of [\"ctrlKey\", \"metaKey\"] as const) {\n\t\t\t\tconst press = new KeyboardEvent(\"keydown\", {\n\t\t\t\t\t...init,\n\t\t\t\t\tkey: \"v\",\n\t\t\t\t\tcode: \"KeyV\",\n\t\t\t\t\t[modifier]: true,\n\t\t\t\t});\n\t\t\t\tel.dispatchEvent(press);\n\n\t\t\t\tif ((await refused(press)) && !blocked.includes(\"shortcut\")) {\n\t\t\t\t\tblocked.push(\"shortcut\");\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!handled) {\n\t\t\t\tconst beforeInput = new InputEvent(\"beforeinput\", {\n\t\t\t\t\t...init,\n\t\t\t\t\tinputType: \"insertFromPaste\",\n\t\t\t\t\tdata: text,\n\t\t\t\t});\n\t\t\t\tel.dispatchEvent(beforeInput);\n\n\t\t\t\tif (await refused(beforeInput)) {\n\t\t\t\t\tblocked.push(\"beforeinput\");\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!handled) {\n\t\t\t\tconst paste = pasteEvent(text);\n\t\t\t\tel.dispatchEvent(paste);\n\n\t\t\t\tif (await refused(paste)) {\n\t\t\t\t\tblocked.push(\"paste\");\n\t\t\t\t} else {\n\t\t\t\t\t// Split boxes are only handled if the page spreads the code, which it may do in a moment.\n\t\t\t\t\tif (boxes.length > 1 && !paste.defaultPrevented) {\n\t\t\t\t\t\tawait waitFor(wrote, REFUSAL_WAIT_MS);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (wrote()) {\n\t\t\t\t\t\thandled = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\t// Taken before the values go back, so that what restoring sets off is not counted.\n\t\t\tsuppressed = Array.from(new Set(suppressedLog.slice(mark)));\n\t\t\trestore(boxes, originals);\n\t\t}\n\n\t\treturn handled ? { blocked: [], handled, suppressed } : { blocked, handled, suppressed };\n\t};\n\n\tconst withFocus = async <T>(el: HTMLInputElement, run: () => Promise<T>): Promise<T> => {\n\t\tconst root = el.getRootNode() as Document | ShadowRoot;\n\t\tconst wasFocused = root.activeElement === el;\n\n\t\tif (!wasFocused) {\n\t\t\tel.focus({ preventScroll: true });\n\n\t\t\tif (root.activeElement !== el) {\n\t\t\t\tel.dispatchEvent(new FocusEvent(\"focus\"));\n\t\t\t\tel.dispatchEvent(new FocusEvent(\"focusin\", { bubbles: true, composed: true }));\n\t\t\t}\n\t\t}\n\n\t\ttry {\n\t\t\treturn await run();\n\t\t} finally {\n\t\t\tif (!wasFocused) {\n\t\t\t\tel.blur();\n\t\t\t}\n\t\t}\n\t};\n\n\tconst focusedElement = (): Element | null => {\n\t\tlet active = document.activeElement;\n\n\t\twhile (active?.shadowRoot?.activeElement) {\n\t\t\tactive = active.shadowRoot.activeElement;\n\t\t}\n\n\t\treturn active;\n\t};\n\n\tconst focusedBefore = focusedElement();\n\tlet selectionBefore: [number, number, \"forward\" | \"backward\" | \"none\"] | null = null;\n\n\tif (focusedBefore instanceof HTMLInputElement || focusedBefore instanceof HTMLTextAreaElement) {\n\t\ttry {\n\t\t\tconst { selectionStart, selectionEnd, selectionDirection } = focusedBefore;\n\n\t\t\tif (selectionStart !== null && selectionEnd !== null) {\n\t\t\t\tselectionBefore = [selectionStart, selectionEnd, selectionDirection ?? \"none\"];\n\t\t\t}\n\t\t} catch {\n\t\t\t// Some input types have no selection to read.\n\t\t}\n\t}\n\n\t/** Put focus back where it was: a page that moves on to the next box as one fills leaves it elsewhere. */\n\tconst restoreFocus = (): void => {\n\t\tconst now = focusedElement();\n\n\t\tif (now !== focusedBefore) {\n\t\t\tif (\n\t\t\t\tfocusedBefore instanceof HTMLElement &&\n\t\t\t\tfocusedBefore !== document.body &&\n\t\t\t\tfocusedBefore.isConnected\n\t\t\t) {\n\t\t\t\tfocusedBefore.focus({ preventScroll: true });\n\t\t\t} else if (now instanceof HTMLElement) {\n\t\t\t\tnow.blur();\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tselectionBefore &&\n\t\t\t(focusedBefore instanceof HTMLInputElement || focusedBefore instanceof HTMLTextAreaElement)\n\t\t) {\n\t\t\ttry {\n\t\t\t\tfocusedBefore.setSelectionRange(...selectionBefore);\n\t\t\t} catch {\n\t\t\t\t// Some input types have no selection to set.\n\t\t\t}\n\t\t}\n\t};\n\n\ttype Probed = { boxes: HTMLInputElement[]; originals: string[]; field: InspectedField };\n\n\tconst elements: Element[] = [];\n\tconst fields: InspectedField[] = [];\n\tconst probed: Probed[] = [];\n\n\tinstallGuards();\n\n\ttry {\n\t\tfor (const candidate of candidates.slice(0, fieldLimit)) {\n\t\t\tconst { el, boxes } = candidate;\n\t\t\tconst probe = probeFor(candidate);\n\t\t\tconst originals = boxes.map((box) => box.value);\n\t\t\tconst startedReadOnly = el.readOnly;\n\t\t\tconst suppressed = new Set<SuppressedAction>();\n\n\t\t\tlet readonlyUntilFocus = false;\n\t\t\tlet attempt: Attempt = { blocked: [], handled: false, suppressed: [] };\n\n\t\t\tconst paste = async (): Promise<Attempt> => {\n\t\t\t\tconst result = await attemptPaste(candidate, probe.text, originals);\n\n\t\t\t\tfor (const action of result.suppressed) {\n\t\t\t\t\tsuppressed.add(action);\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t};\n\n\t\t\tguardForm(el.form);\n\n\t\t\tif (startedReadOnly) {\n\t\t\t\t// Only focus can tell a field that is never editable from one a script unlocks on focus.\n\t\t\t\tattempt = await withFocus(el, async () => {\n\t\t\t\t\treadonlyUntilFocus = !el.readOnly;\n\n\t\t\t\t\treturn el.readOnly ? attempt : paste();\n\t\t\t\t});\n\n\t\t\t\tel.readOnly = true;\n\t\t\t} else {\n\t\t\t\tattempt = await paste();\n\n\t\t\t\t// A handler that inserts through the selection needs focus, so check a refusal again with it.\n\t\t\t\tif (attempt.blocked.length > 0) {\n\t\t\t\t\tattempt = await withFocus(el, paste);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst field: InspectedField = {\n\t\t\t\tkind: candidate.kind,\n\t\t\t\thtml: (el.cloneNode(false) as Element).outerHTML,\n\t\t\t\tautocomplete: autocompleteOf(el),\n\t\t\t\tblocked: attempt.blocked,\n\t\t\t\tinlineHandler: el.closest(\"[onpaste]\") !== null,\n\t\t\t\thandled: attempt.handled,\n\t\t\t\treadonlyUntilFocus,\n\t\t\t\tboxes: boxes.length > 1 ? boxes.length : 0,\n\t\t\t\tsignIn: candidate.signIn,\n\t\t\t\tpartialProbe: probe.partial,\n\t\t\t\tsuppressed: Array.from(suppressed),\n\t\t\t};\n\n\t\t\telements.push(el);\n\t\t\tfields.push(field);\n\t\t\tprobed.push({ boxes, originals, field });\n\t\t}\n\n\t\t// A page may write the pasted text in well after the event, so look once more before leaving:\n\t\t// a value that turns up late is put back, and shows that the paste was taken after all.\n\t\tif (probed.length > 0) {\n\t\t\tawait sleep(FINAL_SETTLE_MS);\n\n\t\t\tfor (let round = 0; round < 2; round++) {\n\t\t\t\tlet restored = false;\n\n\t\t\t\tfor (const { boxes, originals, field } of probed) {\n\t\t\t\t\tif (wroteInto(boxes, originals)) {\n\t\t\t\t\t\tfield.handled = true;\n\t\t\t\t\t\tfield.blocked = [];\n\t\t\t\t\t}\n\n\t\t\t\t\trestored = restore(boxes, originals) || restored;\n\t\t\t\t}\n\n\t\t\t\tif (!restored) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tawait sleep(RECHECK_MS);\n\t\t\t}\n\t\t}\n\t} finally {\n\t\tfor (const { boxes, originals } of probed) {\n\t\t\trestore(boxes, originals);\n\t\t}\n\n\t\tfor (const unhook of unhooks.reverse()) {\n\t\t\tunhook();\n\t\t}\n\n\t\trestoreFocus();\n\t}\n\n\t(window as unknown as Record<string, unknown>)[stashKey] = elements;\n\n\treturn { fields, total: candidates.length };\n}\n","import type { InspectedField } from \"./browser-scripts\";\n\n/**\n * What stands between the field and a password manager or a paste.\n *\n * - `paste-blocked`: the page cancels the `paste` event and the field stays empty.\n * - `partial-paste-refused`: the page cancels the `paste` event for a one-time code or numeric PIN.\n * The audit pastes those a digit short, so the page may only be turning away the wrong length.\n * - `paste-may-be-blocked`: the page cancels only the paste key press or the `beforeinput` event.\n * - `split-code-paste-unhandled`: a code split into one-character boxes takes one character of a\n * pasted code.\n * - `readonly-until-focus`: the field is `readonly` until focused, which hides it from autofill.\n * - `autocomplete-off`: `autocomplete=\"off\"` on the field or its form.\n * - `new-password-on-sign-in`: `autocomplete=\"new-password\"` on the password of a sign-in form.\n * - `no-autofill-hint`: a one-time-code field without `autocomplete=\"one-time-code\"`.\n */\nexport type PasteBlockingSignal =\n\t| \"paste-blocked\"\n\t| \"partial-paste-refused\"\n\t| \"paste-may-be-blocked\"\n\t| \"split-code-paste-unhandled\"\n\t| \"readonly-until-focus\"\n\t| \"autocomplete-off\"\n\t| \"new-password-on-sign-in\"\n\t| \"no-autofill-hint\";\n\nexport type Verdict = \"failed\" | \"review\";\n\nexport type FieldClassification = {\n\t/** Every signal that applies, most serious first. Empty when the field passes. */\n\tsignals: PasteBlockingSignal[];\n\t/** `failed` when the first signal is `paste-blocked`, `review` for any other, null for none. */\n\tverdict: Verdict | null;\n};\n\n/**\n * Decide what, if anything, stops a password manager or a paste from filling an inspected field.\n */\nexport function classifyField(field: InspectedField): FieldClassification {\n\tconst signals: PasteBlockingSignal[] = [];\n\tconst tokens = (field.autocomplete ?? \"\").split(/\\s+/);\n\n\tif (field.blocked.includes(\"paste\")) {\n\t\tsignals.push(field.partialProbe ? \"partial-paste-refused\" : \"paste-blocked\");\n\t} else if (field.blocked.length > 0) {\n\t\tsignals.push(\"paste-may-be-blocked\");\n\t} else if (field.boxes > 0 && !field.handled && !field.readonlyUntilFocus) {\n\t\tsignals.push(\"split-code-paste-unhandled\");\n\t}\n\n\tif (field.readonlyUntilFocus) {\n\t\tsignals.push(\"readonly-until-focus\");\n\t}\n\n\tif (tokens.includes(\"off\")) {\n\t\tsignals.push(\"autocomplete-off\");\n\t}\n\n\tif (field.kind === \"password\" && field.signIn && tokens.includes(\"new-password\")) {\n\t\tsignals.push(\"new-password-on-sign-in\");\n\t}\n\n\tif (\n\t\tfield.kind === \"one-time-code\" &&\n\t\tfield.boxes === 0 &&\n\t\t!tokens.includes(\"one-time-code\") &&\n\t\t!tokens.includes(\"off\")\n\t) {\n\t\tsignals.push(\"no-autofill-hint\");\n\t}\n\n\tif (signals.length === 0) {\n\t\treturn { signals, verdict: null };\n\t}\n\n\treturn { signals, verdict: signals[0] === \"paste-blocked\" ? \"failed\" : \"review\" };\n}\n"],"mappings":";AAAA;AAAA,EAEC;AAAA,EACA;AAAA,OACM;AACP,SAAS,oBAAoB;;;ACyD7B,eAAsB,wBACrB,UACA,YAC+B;AAC/B,QAAM,aAAa,oBAAI,IAAI,CAAC,QAAQ,OAAO,UAAU,SAAS,YAAY,UAAU,KAAK,CAAC;AAC1F,QAAM,i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,QAAQ,WAAW;AAAA,MAC1C;AAAA,IACD;AAAA,EACD,UAAE;AACD,UAAM,uBAAuB,SAAS,SAAS;AAAA,EAChD;AACD;","names":["event"]}
@@ -0,0 +1,51 @@
1
+ import type { AuthFieldKind, BlockMechanism, SuppressedAction } from "./browser-scripts";
2
+ import type { PasteBlockingSignal } from "./classify";
3
+ /** How a refused paste was traced: to an `onpaste` attribute, or to a listener added by script. */
4
+ export type PasteBlockDetection = "inline-handler" | "event-listener";
5
+ export type PasteBlockingField = {
6
+ /** Selector for the field (see getSelector). For a split code, its first box. */
7
+ selector: string;
8
+ /** Truncated opening tag. */
9
+ html: string;
10
+ kind: AuthFieldKind;
11
+ /** Every signal that applies, most serious first. Empty when the field passes. */
12
+ signals: PasteBlockingSignal[];
13
+ /**
14
+ * Every way the page refused a synthetic paste while leaving the field unchanged: the `paste`
15
+ * event, the `beforeinput` event for a paste, or the Ctrl+V or Cmd+V key press.
16
+ */
17
+ blocked: BlockMechanism[];
18
+ /** Where the refusal came from, or null when nothing was refused. */
19
+ detectedBy: PasteBlockDetection | null;
20
+ /** The `autocomplete` of the field, or of its form when it has none. Null if unset. */
21
+ autocomplete: string | null;
22
+ /** How many one-character boxes a split code has, or null for an ordinary field. */
23
+ boxes: number | null;
24
+ /**
25
+ * The text pasted was a digit short of what the field takes. One-time codes and numeric PINs are
26
+ * pasted this way so the page never holds a complete code that it could send for verification.
27
+ */
28
+ partialProbe: boolean;
29
+ /**
30
+ * What the page tried to do in response to the paste and was stopped from doing: submit a form
31
+ * (`submit`), or send a `fetch`, `XMLHttpRequest` or `sendBeacon` request (`request`).
32
+ */
33
+ suppressed: SuppressedAction[];
34
+ };
35
+ export type PasteBlockingResult = {
36
+ /** Fields whose `paste` event the page cancels, so nothing can be pasted into them. */
37
+ failed: PasteBlockingField[];
38
+ /** Fields that may keep a password manager or a paste out, for a human to check. */
39
+ needsReview: PasteBlockingField[];
40
+ passed: PasteBlockingField[];
41
+ /** Full counts. Each field list stops at `reportLimit`. */
42
+ summary: {
43
+ /** Rendered authentication fields inspected, up to `fieldLimit`. Zero means inapplicable. */
44
+ checked: number;
45
+ failed: number;
46
+ needsReview: number;
47
+ passed: number;
48
+ /** Authentication fields past `fieldLimit`, which were not inspected. */
49
+ unchecked: number;
50
+ };
51
+ };
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
- "name": "@a11y-pulse/paste-blocking-audit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@a11y-pulse/paste-blocking-audit",
3
+ "version": "0.12.0",
4
+ "description": "WCAG 3.3.8 Accessible Authentication audit that finds password, username and one-time-code fields which block pasting or autofill, so a password manager cannot fill them.",
5
+ "type": "module",
6
+ "license": "SEE LICENSE IN LICENSE.md",
7
+ "author": "A11y Pulse",
8
+ "homepage": "https://github.com/A11y-Pulse/audits/tree/main/packages/paste-blocking-audit#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/A11y-Pulse/audits.git",
12
+ "directory": "packages/paste-blocking-audit"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/A11y-Pulse/audits/issues"
16
+ },
17
+ "keywords": [
18
+ "accessibility",
19
+ "a11y",
20
+ "wcag",
21
+ "accessible-authentication",
22
+ "paste",
23
+ "password-manager",
24
+ "audit"
25
+ ],
26
+ "engines": {
27
+ "node": ">=22"
28
+ },
29
+ "exports": {
30
+ ".": {
31
+ "source": "./src/index.ts",
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "README.md",
39
+ "LICENSE.md"
40
+ ],
41
+ "scripts": {
42
+ "build": "tsup && tsc -p tsconfig.build.json",
43
+ "typecheck": "tsc --noEmit",
44
+ "lint": "biome check",
45
+ "lint:fix": "biome check --fix",
46
+ "test:unit": "vitest run",
47
+ "test:integration": "vitest run --config vitest.integration.config.ts",
48
+ "test": "npm run typecheck && npm run test:unit",
49
+ "prepublishOnly": "npm run build"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "dependencies": {
55
+ "@a11y-pulse/browser-adaptor": "0.12.0"
56
+ },
57
+ "devDependencies": {
58
+ "happy-dom": "^21.0.4",
59
+ "playwright-core": "^1.65.0",
60
+ "puppeteer": "^25.17.0"
61
+ }
62
+ }