Keep more shapes of phones, codes, tokens, emails and IP addresses private

Review found "Alice 555-0100" sent as a Japanese postcode, recovery phrases
with a repeated word, a capitalised bearer token, codes after a lower-case
label in other cases ("verification code Abc", "PIN aBcD"), "john at
gmail.com" and "(dot)" forms, passport numbers of digits only, "ID AB123"
and IPv6 addresses. They now stay in the browser, and the suggester never
sends a line of more than eight words. "Bearer Island, Canada", "bearer
island", a ZIP+4 after two spaces and a Japanese postcode after Japanese
script are looked up again.

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-18 16:59:35 -08:00
1 parent 8885177e2e
commit 35049fd7f7
3 files changed
+161 -27

No files matched your search

+22 -12
View File
@@ -8029,7 +8029,8 @@ and errors, keeping the separate Location draft intact.
While typing, a short line (six words or fewer, no `?`, not a command,
coordinates, a hex code, a callsign such as UAL2110 or N123AB, and nothing
that may be private) is sent to
Photon for place suggestions: at most one request every 500 ms per tab,
Photon for place suggestions (the suggester itself never sends a line of
more than eight words): at most one request every 500 ms per tab,
and none for a minute after a refusal. Photon is the keyless geocoder the
place search already uses; a submitted search is not part of this spacing.
A line that may be one name ("Satellite Beach") is looked up whole. While
@@ -8044,10 +8045,13 @@ any line with: an "@" with something right on both sides, ending a word,
starting a lowercase handle ("@jdoe"), or spaced before a domain ("john @
gmail.com") (an email address or a handle, also while it is typed; spaced, as in "Nanjampeta @
Chandambylu", it is part of a name); an email spelled around a filter
("john(at)gmail.com", "john[at]gmail[dot]com", "john at gmail dot de"); an
IP address ("10.0.0.1"); a wallet's recovery phrase (12, 15, 18, 21 or 24
different lower-case words of three to eight letters); a line that is one
lower-case word of twenty letters or more (a passphrase run together); seven digits or more with nothing but spaces,
("john(at)gmail.com", "john[at]gmail[dot]com", "john at gmail dot de",
"john at gmail.com", "john at gmail (dot) com"); an IP address
("10.0.0.1", "::1", "fe80::1"); a wallet's recovery phrase (12, 15, 18, 21
or 24 lower-case words of three to eight letters, not starting as a request
does); a line that is one lower-case word of twenty letters or more (a
passphrase run together; one written with a capital, or spaced into words,
cannot be told from a name and is not caught); seven digits or more with nothing but spaces,
punctuation, symbols or format characters between them (a phone, card,
SSN or account number or its start: "+1 415 555", "4111 1111", "123 45
6789", "123456789", "4111.1111.1111.1111", "123–45–6789"; a street address's house number
@@ -8056,22 +8060,28 @@ a polite word such as "thanks" after the digits is not a city): five digits, or
the city "00-950", "111 21", "125009", "1100-053", or four digits after a
comma ("Straße 120, 1070 Wien"); and so are a US ZIP+4 after a state's
code or name ("Alice 12345-6789" and "Jo 12345-6789" stay private),
a Brazilian CEP, a Japanese postcode after "〒", before the address or
after a place's name ("Shibuya 150-0002"), and
a Brazilian CEP, a Japanese postcode after "〒" or next to the address in
Japanese script ("東京都千代田区100-0001"; after a Latin name, as in
"Shibuya 150-0002", it reads as a phone number), and
digits on either side of "#", so "Hauptstrasse 12 10115 Berlin", "DC
20500-0003", "〒100-0001 東京都千代田区" and "Calle 100 # 19-61" are places,
while a seven-digit postcode alone such as "Tel Aviv 6100000" still reads
as private); a phone number written with dots; two letters, two
digits and ten more letters or digits (an IBAN's shape); "password",
"passcode", "passwd", "pw" or "pwd" followed by anything, "bearer"
followed by anything but a capitalised name ("Bearer Island" is a place),
followed by anything but a short capitalised name or a place word such as
island or lake ("Bearer Island", "bearer island" are places),
"ssn" followed by a digit ("SSN Station" is a place), "token", "secret",
"api key", "key" or "pass" followed by ":" or "=", a licence, plate,
passport, membership, account, policy, ticket, booking, confirmation or
reference number with letters and digits after its label ("license
ABC1234"), "otp", "2fa", "mfa", "cvv", "cvc" or a verification, one-time,
security, auth or login code followed by a code in any case that is not a
capitalised name ("otp abcdef"; "OTP Bank" is a place), a
reference number with a digit after its label ("license ABC1234",
"passport no. 123456"), "ID" in capitals followed by a number ("ID
AB123"), "otp", "2fa", "mfa", "cvv", "cvc" or a verification, one-time,
security, auth or login code followed by a code (any value after a label
in lower case, "verification code Abc", also before "thanks"; after a label
written as a name, any value that is not one: "OTP Bank" and "Security
Code Plaza" are places), a "pin" or door, access, gate, alarm or entry
code followed by a value in mixed case ("PIN aBcD"), a
door, access, gate, alarm, entry or security code followed by a digit, "api
key", "access token" or "secret key" followed by a word of six characters
or more, the word for "password" in the interface's languages
+88 -14
View File
@@ -67,6 +67,13 @@ export function onlyNumbersLookPrivate(text) {
);
}
/** How a typed request starts, unlike a recovery phrase's first word. */
const REQUEST_START =
/^(?:show|hide|turn|switch|find|search|go|fly|take|zoom|open|close|play|what|where|when|which|who|how|why|list|display|enable|disable|remove|clear|follow|track)\b/;
/** The most words a line sent for place suggestions may have. */
const SUGGEST_MAX_WORDS = 8;
/**
* Words that say a number is an account, a card, a phone or a secret, in the
* interface's languages where they differ ("Karte", "Telefon", "tarjeta").
@@ -85,7 +92,8 @@ function foldLine(text) {
.normalize('NFKC')
.replace(/\p{Cf}/gu, '')
.replace(/[\u2018\u2019]/g, "'")
.replace(/(?![0-9])\p{Nd}/gu, '0');
.replace(/(?![0-9])\p{Nd}/gu, '0')
.replace(/\s+/g, ' ');
}
/** A US ZIP+4 after a state's code or name, as an address writes it. */
@@ -122,21 +130,45 @@ function privacyReason(text) {
return 'other';
// An email written around a filter: "john(at)gmail.com",
// "john[at]gmail[dot]com", "john at gmail dot com".
// Also "john at gmail.com" and a "(dot)" or "[dot]" in any of them.
if (
/[\p{L}\p{N}._%+-]\s*[([{<]\s*at\s*[)\]}>]\s*[\p{L}\p{N}-]/iu.test(line) ||
/\b\S+\s+at\s+\S+\s+dot\s+\p{L}{2,6}\b/iu.test(line)
/\b\S+\s+at\s+\S+\s+(?:dot|[([{<]\s*dot\s*[)\]}>])\s+\p{L}{2,24}\b/iu.test(
line,
) ||
/\b\S+\s+at\s+[\p{L}\p{N}-]+\s*[([{<]\s*dot\s*[)\]}>]\s*\p{L}{2,24}\b/iu.test(
line,
) ||
/\b[\p{L}\p{N}._%+-]+\s+at\s+[\p{L}\p{N}-]+(?:\.[\p{L}\p{N}-]+)*\.(?:com|net|org|edu|gov|mil|io|co|me|info|biz|app|dev|ai|[a-z]{2})\b/iu.test(
line,
)
)
return 'other';
// An IP address ("10.0.0.1").
if (/(?<![\d.])\d{1,3}(?:\.\d{1,3}){3}(?![\d.])/.test(line)) return 'other';
// A wallet's recovery phrase: 12, 15, 18, 21 or 24 different words, all
// of three to eight letters in lower case ("abandon ability able …"). A
// request that long nearly always has a short word ("to", "in", "me").
// An IPv6 address ("::1", "fe80::1%eth0", "2001:db8:0:0:0:0:2:1"): hex
// groups with "::", or five colons or more (a time has two).
if (
line.split(' ').some((token) => {
const bare = token.replace(/^[[(]+|[\]),.;]+$/g, '').replace(/%\w+$/, '');
const colons = (bare.match(/:/g) || []).length;
return (
/^[0-9a-f:.]+$/i.test(bare) &&
colons >= 2 &&
(bare.includes('::') || colons >= 5)
);
})
)
return 'other';
// A wallet's recovery phrase: 12, 15, 18, 21 or 24 words, all of three
// to eight letters in lower case ("abandon ability able …"), unless it
// starts as a request does ("show flights over texas …"). A line that
// long is never sent for suggestions anyway (see SUGGEST_MAX_WORDS).
const words = line.trim().split(/\s+/);
if (
[12, 15, 18, 21, 24].includes(words.length) &&
new Set(words).size === words.length &&
words.every((word) => /^[a-z]{3,8}$/.test(word))
words.every((word) => /^[a-z]{3,8}$/.test(word)) &&
!REQUEST_START.test(line)
)
return 'other';
// A passphrase run together ("correcthorsebatterystaple"): a line that
@@ -190,7 +222,7 @@ function privacyReason(text) {
.replace(US_ZIP4, ' x ')
.replace(/\b\d{5}-\d{3}\b/g, ' x ')
.replace(
/〒\s?\d{3}-\d{4}|\b\d{3}-\d{4}(?=\s*[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}])|(?<=\p{L}{3,},?\s)\d{3}-\d{4}(?=\s*$|,)/gu,
/〒\s?\d{3}-\d{4}|\b\d{3}-\d{4}(?=\s*[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}])|(?<=[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]\s*)\d{3}-\d{4}\b/gu,
' x ',
)
.replace(/#/g, ' x ')
@@ -221,7 +253,12 @@ function privacyReason(text) {
/\b(?:token|secret|api[ _-]?key|key|pass)\s*[:=]\s*\S/i.test(line) ||
// A number on a document or account after its label: "license ABC1234",
// "passport X1234567", "plate 7ABC123", "member no. 12345".
/\b(?:licen[cs]e|plate|passport|member(?:ship)?|account|acct|policy|ticket|booking|confirmation|ref(?:erence)?)(?:\s+(?:no\.?|number|#|is))*\s*[:=#]?\s+(?=[a-z0-9-]*\d)(?=[a-z0-9-]*[a-z])[a-z0-9-]{4,}/i.test(
/\b(?:licen[cs]e|plate|passport|member(?:ship)?|account|acct|policy|ticket|booking|confirmation|ref(?:erence)?)(?:\s+(?:no\.?|number|#|is))*\s*[:=#]?\s+(?=[a-z0-9-]*\d)[a-z0-9-]{4,}/i.test(
line,
) ||
// An identity number after "ID" in capitals ("ID AB123"); "Id" and
// "id" are words.
/\bID(?:\s+(?:no\.?|number|#|is))*\s*[:=#]?\s+(?=[A-Za-z0-9-]*\d)[A-Za-z0-9-]{4,}/.test(
line,
) ||
/\b(?:my secret is|passphrase|mnemonic|seed phrase|recovery phrase)\b\s*[:=]?\s*\S/i.test(
@@ -261,10 +298,21 @@ function privacyReason(text) {
/** A value after "bearer" that is not a capitalised name ("Bearer Island"). */
function bearerToken(line) {
const match = /\bbearer\b\s*[:=#]?\s*(\S+)/i.exec(line);
return Boolean(match) && !/^\p{Lu}\p{Ll}+$/u.test(match[1]);
for (const match of line.matchAll(/\bbearer\b\s*[:=#]?\s*(\S+)/gi)) {
const value = match[1].replace(/[,.;:!?)]+$/, '');
// A name: capitalised and short ("Bearer Island, Canada"), or a word
// a place's name is made of ("bearer island").
if (/^\p{Lu}\p{Ll}{1,11}$/u.test(value) || PLACE_WORDS.test(value))
continue;
return true;
}
return false;
}
/** Words a place's name is made of, after a label word ("bearer island"). */
const PLACE_WORDS =
/^(?:island|islands|isle|lake|creek|river|point|bay|mountain|mount|hill|hills|valley|station|road|street|lane|avenue|park|beach|falls|springs?|county|city|town|village)$/i;
/**
* A code after a label that can only be a code, without a colon ("PIN
* A7B2", "verification code ABCDEF", "otp 7GH2K"): holding a digit, or in
@@ -275,11 +323,30 @@ function codeAfterLabel(line) {
// Labels that only ever name a code take one in lower case too ("otp
// abcdef", "cvv abc", "verification code abcdef"); a capitalised word
// after them is a name ("OTP Bank", "MFA Boston").
// After a label in lower case, any value is a code ("verification code
// Abc"); after one written as a name, only a value that is not one.
const coded =
/\b(?:otp|2fa|mfa|cvv|cvc|(?:verification|one-time|security|auth|login) code)(?:\s+is)?\s+([a-z0-9][a-z0-9-]{2,})\s*[.!]?\s*$/i.exec(
/\b((?:otp|2fa|mfa|cvv|cvc|(?:verification|one-time|security|auth|login) code)(?:\s+is)?)\s+([a-z0-9][a-z0-9-]{2,})(?:\s+(?:thanks|thank you|thx|please|pls|ok))?\s*[.!]?\s*$/i.exec(
line,
);
if (coded && !/^\p{Lu}(?:\p{Ll}+|\p{Lu}+)$/u.test(coded[1])) return true;
if (coded) {
const [, label, value] = coded;
const labelIsName = /\p{Lu}/u.test(label);
if (!labelIsName) return true;
if (!/^\p{Lu}(?:\p{Ll}+|\p{Lu}+)$/u.test(value)) return true;
}
// A value in mixed case that is no name ("PIN aBcD", "gate code aBcD").
const mixed =
/\b(?:pin|(?:door|access|gate|alarm|entry) code)(?:\s+is)?\s+([a-z0-9-]{4,})\s*[.!]?\s*$/i.exec(
line,
);
if (
mixed &&
/\p{Ll}/u.test(mixed[1]) &&
/\p{Lu}/u.test(mixed[1]) &&
!/^\p{Lu}\p{Ll}+$/u.test(mixed[1])
)
return true;
const match =
/\b((?:pin|cvv|cvc|otp|2fa|mfa|(?:door|access|gate|alarm|entry|security|verification|one-time|auth|login) code)(?:\s+is)?)\s+([a-z0-9][a-z0-9-]{3,})\s*[.!]?\s*$/i.exec(
line,
@@ -394,7 +461,14 @@ export function createPlaceSuggester({
const text = String(query ?? '')
.trim()
.slice(0, MAX_QUERY_CHARS);
if (!enabled || text.length < minPlaceChars(text) || mayBePrivate(text))
// A line longer than a place's name is never sent: a pasted sentence
// or phrase is no place, and may be private in ways not read here.
if (
!enabled ||
text.length < minPlaceChars(text) ||
text.split(/\s+/).length > SUGGEST_MAX_WORDS ||
mayBePrivate(text)
)
return [];
const language = (globalThis.document?.documentElement?.lang || 'en')
.slice(0, 2)
+51 -1
View File
@@ -460,7 +460,13 @@ test('places that only looked private are looked up', () => {
'Akiak',
'Bearer Island',
'SSN Station',
'Shibuya 150-0002',
'Bearer Island, Canada',
'bearer island',
'Washington DC 20500-0003',
'東京都千代田区100-0001',
'Security Code Plaza',
'Idaho Falls',
'meet at 12:30:45',
'Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch',
'OTP Bank',
// A long request is not a recovery phrase.
@@ -511,3 +517,47 @@ test('a house is named by its number and street in the order its country writes
['Mittenwald Au 3', 'Mittenwald Au 5'],
);
});
test('codes, phones, tokens, emails and addresses in further shapes stay private', () => {
for (const line of [
// A phone's three and four digits after a name, as a postcode can't be
// told from it ("Shibuya 150-0002" is refused for that).
'Alice 555-0100',
'Shibuya 150-0002',
`${Array(23).fill('abandon').join(' ')} art`,
'Bearer Abcdefghijklmnopqrstuvwxyz',
'Bearer Island bearer abcdef',
'verification code Abc',
'verification code ABC',
'verification code abc thanks',
'PIN aBcD',
'gate code aBcD',
'john at gmail.com',
'john at gmail (dot) com',
'john at gmail [dot] com',
'john at gmail dot technology',
'passport number 123456',
'passport no. 123456',
'ID AB123',
'::1',
'fe80::1',
'2001:db8:0:0:0:0:2:1',
])
assert.equal(mayBePrivate(line), true, line);
});
test('a line longer than a place name is never sent for suggestions', async () => {
let sent = 0;
const service = createPlaceSuggester({
endpoint: 'https://fixture.test/api/',
fetchImpl: async () => {
sent++;
return Response.json({ features: [] });
},
});
assert.deepEqual(
await service.suggest('one two three four five six seven eight nine'),
[],
);
assert.equal(sent, 0);
});