Skip to content

Commit 26d05f3

Browse files
authored
Scam protection (#1518)
1 parent 931740f commit 26d05f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+508
-250
lines changed

special-pages/pages/special-error/app/components/AdvancedInfo.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export function VisitSiteLink({ elemRef }) {
3434

3535
export function AdvancedInfoHeading() {
3636
const heading = useAdvancedInfoHeading();
37+
if (!heading) return null;
3738

3839
return (
3940
<header className={styles.heading}>
@@ -46,6 +47,7 @@ export function AdvancedInfoHeading() {
4647

4748
export function AdvancedInfoContent() {
4849
const content = useAdvancedInfoContent();
50+
if (!content.length) return null;
4951

5052
return (
5153
<div className={styles.content}>

special-pages/pages/special-error/app/components/App.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ function PageTitle() {
3434
useEffect(() => {
3535
switch (kind) {
3636
case 'malware':
37-
document.title = t('malwareTabTitle');
38-
break;
3937
case 'phishing':
40-
document.title = t('phishingTabTitle');
38+
case 'scam':
39+
document.title = t('maliciousSiteTabTitle');
4140
break;
4241
default:
4342
document.title = t('sslPageHeading');

special-pages/pages/special-error/app/components/Components.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const platforms = {
2929
*/
3030
function idForError(errorData) {
3131
const { kind } = errorData;
32-
if (kind === 'phishing' || kind === 'malware') {
32+
if (kind === 'malware' || kind === 'phishing' || kind === 'scam') {
3333
return kind;
3434
}
3535

special-pages/pages/special-error/app/components/Warning.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ export function LeaveSiteButton() {
5353
}
5454

5555
export function WarningHeading() {
56-
const { kind } = useErrorData();
5756
const heading = useWarningHeading();
57+
if (!heading) return null;
58+
59+
const { kind } = useErrorData();
5860
const platformName = usePlatformName();
5961
const isMobile = useIsMobile();
6062

@@ -84,6 +86,7 @@ export function WarningHeading() {
8486

8587
export function WarningContent() {
8688
const content = useWarningContent();
89+
if (!content.length) return null;
8790

8891
return (
8992
<div className={styles.content}>

special-pages/pages/special-error/app/components/Warning.module.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
margin-top: calc(-1 * var(--sp-2));
6161
}
6262

63-
& .phishing .icon, & .malware .icon {
63+
& .phishing .icon, & .malware .icon, & .scam .icon {
6464
background-image: url(../../../../shared/assets/img/icons/Malware-Site-96.svg);
6565
margin-left: calc(-1 * var(--sp-2));
6666
margin-right: calc(-1 * var(--sp-1));
@@ -86,6 +86,7 @@
8686

8787
& .content {
8888
text-align: center;
89+
text-wrap: balance;
8990
white-space: pre-line; /* Preserve line breaks on all screen sizes */
9091
}
9192

@@ -116,7 +117,7 @@
116117
background-image: url(../../../../shared/assets/img/icons/Shield-Alert-128.svg);
117118
}
118119

119-
& .phishing .icon, & .malware .icon {
120+
& .phishing .icon, & .malware .icon, & .scam .icon {
120121
background-image: url(../../../../shared/assets/img/icons/Malware-Site-128.svg);
121122
}
122123

@@ -166,7 +167,7 @@
166167
margin-top: calc(-1 * var(--sp-2));
167168
}
168169

169-
& .phishing .icon, & .malware .icon {
170+
& .phishing .icon, & .malware .icon, & .scam .icon {
170171
background-image: url(../../../../shared/assets/img/icons/Malware-Site-96.svg);
171172
margin-left: calc(-1 * var(--sp-2));
172173
margin-right: calc(-1 * var(--sp-1));

special-pages/pages/special-error/app/hooks/ErrorStrings.jsx

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const reportSiteAnchorTagParams = (urlParam) => {
4949
* @typedef {import("../../types/special-error.js").SSLInvalidCertificate} SSLInvalidCertificate
5050
* @typedef {import("../../types/special-error.js").SSLSelfSignedCertificate} SSLSelfSignedCertificate
5151
* @typedef {import("../../types/special-error.js").SSLWrongHost} SSLWrongHost
52-
* @typedef {import("../../types/special-error.js").PhishingAndMalware} PhishingAndMalware
52+
* @typedef {import("../../types/special-error.js").MaliciousSite} MaliciousSite
5353
* @typedef {SSLExpiredCertificate|SSLInvalidCertificate|SSLSelfSignedCertificate|SSLWrongHost} SSLError
5454
*/
5555

@@ -60,16 +60,15 @@ export function useWarningHeading() {
6060
const { t } = useTypedTranslation();
6161
const { kind } = useErrorData();
6262

63-
if (kind === 'phishing') {
64-
return t('phishingPageHeading').replace('{newline}', '\n');
65-
}
66-
67-
if (kind === 'malware') {
68-
return t('malwarePageHeading').replace('{newline}', '\n');
69-
}
70-
71-
if (kind === 'ssl') {
72-
return t('sslPageHeading');
63+
switch (kind) {
64+
case 'ssl':
65+
return t('sslPageHeading');
66+
case 'malware':
67+
case 'phishing':
68+
case 'scam':
69+
const translationKey = /** @type {const} */ (`${kind}PageHeading`);
70+
return t(translationKey).replace('{newline}', '\n');
71+
default:
7372
}
7473

7574
throw new Error(`Unhandled error kind ${kind}`);
@@ -93,6 +92,11 @@ export function useWarningContent() {
9392
return [<Trans str={text} values={{ a: helpPageAnchorTagParams }} />];
9493
}
9594

95+
if (kind === 'scam') {
96+
const text = t('scamWarningText').replace('{newline}', '\n');
97+
return [<Trans str={text} values={{ a: helpPageAnchorTagParams }} />];
98+
}
99+
96100
if (kind === 'ssl') {
97101
const { domain } = /** @type {SSLError}} */ (errorData);
98102
return [<Trans str={t('sslWarningText', { domain })} values="" />];
@@ -109,16 +113,17 @@ export function useAdvancedInfoHeading() {
109113
const errorData = useErrorData();
110114
const { kind } = errorData;
111115

112-
if (kind === 'phishing' || kind === 'malware') {
113-
const { url } = /** @type {PhishingAndMalware} */ (errorData);
114-
const anchorTagParams = reportSiteAnchorTagParams(url);
115-
const translatioKey = kind === 'phishing' ? 'phishingAdvancedInfoHeading' : 'malwareAdvancedInfoHeading';
116-
117-
return <Trans str={t(translatioKey)} values={{ a: anchorTagParams }} />;
118-
}
119-
120-
if (kind === 'ssl') {
121-
return t('sslAdvancedInfoHeading');
116+
switch (kind) {
117+
case 'ssl':
118+
return t('sslAdvancedInfoHeading');
119+
case 'malware':
120+
case 'phishing':
121+
case 'scam':
122+
const { url } = /** @type {MaliciousSite} */ (errorData);
123+
const anchorTagParams = reportSiteAnchorTagParams(url);
124+
const translationKey = /** @type {const} */ (`${kind}AdvancedInfoHeading`);
125+
return <Trans str={t(translationKey)} values={{ a: anchorTagParams }} />;
126+
default:
122127
}
123128

124129
throw new Error(`Unhandled error kind ${kind}`);
@@ -132,7 +137,7 @@ export function useAdvancedInfoContent() {
132137
const errorData = useErrorData();
133138
const { kind } = errorData;
134139

135-
if (kind === 'phishing' || kind === 'malware') {
140+
if (kind === 'malware' || kind === 'phishing' || kind === 'scam') {
136141
return [];
137142
}
138143

special-pages/pages/special-error/integration-tests/special-error-screenshots.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,11 @@ test.describe('screenshots @screenshots', () => {
3333
await special.openPage({ errorId: 'malware', locale: 'ru' });
3434
await expect(page).toHaveScreenshot('malware-warning-ru.png', { maxDiffPixels });
3535
});
36+
37+
test('Scam warning with advanced info', async ({ page }, workerInfo) => {
38+
const special = SpecialErrorPage.create(page, workerInfo);
39+
await special.openPage({ errorId: 'scam' });
40+
await special.showsAdvancedInfo();
41+
await expect(page).toHaveScreenshot('scam-warning-advanced.png', { maxDiffPixels });
42+
});
3643
});

special-pages/pages/special-error/integration-tests/special-error.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,27 @@ export class SpecialErrorPage {
295295
).toBeVisible();
296296
}
297297

298+
async showsScamPage() {
299+
const { page } = this;
300+
301+
await this.showsPageTitle('Warning: Security Risk');
302+
303+
await expect(page.getByText('Warning: This site may be a security risk', { exact: true })).toBeVisible();
304+
await expect(
305+
page.getByText(
306+
'DuckDuckGo blocked this page because it may be trying to deceive or manipulate you into transferring money, buying counterfeit goods, or installing malware under false pretenses. Learn more',
307+
{ exact: true },
308+
),
309+
).toBeVisible();
310+
await this.showsAdvancedInfo();
311+
await expect(
312+
page.getByText(
313+
'If you believe this website is safe, you can report an error. You can still visit the website at your own risk.',
314+
{ exact: true },
315+
),
316+
).toBeVisible();
317+
}
318+
298319
/**
299320
* Clicks on advanced link to show expanded info
300321
*

special-pages/pages/special-error/integration-tests/special-error.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ test.describe('special-error', () => {
6060
await special.showsMalwarePage();
6161
});
6262

63+
test('shows scam warning', async ({ page }, workerInfo) => {
64+
const special = SpecialErrorPage.create(page, workerInfo);
65+
await special.openPage({ errorId: 'scam' });
66+
await special.showsScamPage();
67+
});
68+
6369
test('leaves site', async ({ page }, workerInfo) => {
6470
const special = SpecialErrorPage.create(page, workerInfo);
6571
await special.openPage({ errorId: 'ssl.expired' });
@@ -92,6 +98,16 @@ test.describe('special-error', () => {
9298
await special.opensNewPage('Learn more', expectedURL);
9399
});
94100

101+
test('opens scam help page in a new window', async ({ page }, workerInfo) => {
102+
const special = SpecialErrorPage.create(page, workerInfo);
103+
await special.overrideTestLinks();
104+
105+
const expectedURL = `${phishingMalwareHelpPageURL}`;
106+
107+
await special.openPage({ errorId: 'scam' });
108+
await special.opensNewPage('Learn more', expectedURL);
109+
});
110+
95111
test('opens report form in a new window', async ({ page, browser }, workerInfo) => {
96112
const special = SpecialErrorPage.create(page, workerInfo);
97113
await special.overrideTestLinks();

special-pages/pages/special-error/messages/initialSetup.response.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
"oneOf": [
2626
{
2727
"type": "object",
28-
"title": "Phishing and Malware",
28+
"title": "Malicious Site",
2929
"required": ["kind", "url"],
3030
"properties": {
3131
"kind": {
3232
"type": "string",
33-
"enum": ["phishing", "malware"]
33+
"enum": ["phishing", "malware", "scam"]
3434
},
3535
"url": {
3636
"type": "string"

special-pages/pages/special-error/public/locales/bg/special-error.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
"title" : "Поемане на риска и отваряне на сайта",
2525
"note" : "Button shown in an error page that warns users of security risks on a website due to Phishing or Malware issues. The buttons allows the user to visit the website anyway despite the risks."
2626
},
27+
"maliciousSiteTabTitle" : {
28+
"title" : "Предупреждение: Риск за сигурността",
29+
"note" : "Title shown in the browser window or tab when the current page may be a security risk due to phishing"
30+
},
2731
"malwarePageHeading" : {
2832
"title" : "Предупреждение: Този сайт може да представлява{newline}риск за сигурността",
2933
"note" : "Title shown in an error page that warn users of security risks on a website due to malware distribution. The {newline} tag should not be translated. It should be placed within the sentence to avoid having a single word hanging on the last line"
3034
},
31-
"malwareTabTitle" : {
32-
"title" : "Предупреждение: Риск за сигурността",
33-
"note" : "Title shown in the browser window or tab when the current page may be a security risk due to malware"
34-
},
3535
"malwareWarningText" : {
3636
"title" : "DuckDuckGo блокира тази страница, защото тя може да разпространява зловреден софтуер, който да компрометира устройството ви или да открадне личната ви информация.{newline}<a>Научете повече</a>",
3737
"note" : "Error description shown in an error page that warns users of security risks on a website due to malware distribution. The {newline} tag should not be translated. It should be placed before the translated <a>Learn More</a> text."
@@ -44,10 +44,6 @@
4444
"title" : "Предупреждение: Този сайт може да представлява{newline}риск за сигурността",
4545
"note" : "Title shown in an error page that warn users of security risks on a website due to Phishing issues. The {newline} tag should not be translated. It should be placed within the sentence to avoid having a single word hanging on the last line"
4646
},
47-
"phishingTabTitle" : {
48-
"title" : "Предупреждение: Риск за сигурността",
49-
"note" : "Title shown in the browser window or tab when the current page may be a security risk due to phishing"
50-
},
5147
"phishingWarningText" : {
5248
"title" : "Този уебсайт може да имитира легитимен сайт, за да ви подмами да предоставите лична информация, като например пароли или номера на кредитни карти.{newline}<a>Научете повече</a>",
5349
"note" : "Error description shown in an error page that warns users of security risks on a website due to Phishing issues. The {newline} tag should not be translated. It should be placed before the translated <a>Learn More</a> text."
@@ -56,6 +52,18 @@
5652
"title" : "Ако смятате, че този уебсайт е безопасен, можете да <a>съобщите за грешка</a>. Все пак можете да посетите уебсайта на свой собствен риск.",
5753
"note" : "Title of the Advanced info section shown in an error page that warns users of security risks on a website due to malware distribution."
5854
},
55+
"scamPageHeading" : {
56+
"title" : "Предупреждение: Този сайт може да представлява{newline}риск за сигурността",
57+
"note" : "Title shown in an error page that warn users of security risks on a website due to suspected scam attempts. The {newline} tag should not be translated. It should be placed within the sentence to avoid having a single word hanging on the last line"
58+
},
59+
"scamWarningText" : {
60+
"title" : "DuckDuckGo блокира тази страница, защото тя може да се опитва да Ви измами или манипулира да преведете пари, да купите фалшиви стоки или да инсталирате зловреден софтуер под фалшив претекст.{newline}<a>Научете повече</a>",
61+
"note" : "Error description shown in an error page that warns users of security risks on a website due to suspected scam attempts. The {newline} tag should not be translated. It should be placed before the translated <a>Learn More</a> text."
62+
},
63+
"scamAdvancedInfoHeading" : {
64+
"title" : "Ако смятате, че този уебсайт е безопасен, можете да <a>съобщите за грешка</a>. Все пак можете да посетите уебсайта на свой собствен риск.",
65+
"note" : "Title of the Advanced info section shown in an error page that warns users of security risks on a website due to suspected scam attempts."
66+
},
5967
"sslPageHeading" : {
6068
"title" : "Предупреждение: Този сайт може да не е сигурен",
6169
"note" : "Title shown in an error page that warn users of security risks on a website due to SSL issues"

special-pages/pages/special-error/public/locales/cs/special-error.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
"title" : "Přijmout riziko a přejít na stránku",
2525
"note" : "Button shown in an error page that warns users of security risks on a website due to Phishing or Malware issues. The buttons allows the user to visit the website anyway despite the risks."
2626
},
27+
"maliciousSiteTabTitle" : {
28+
"title" : "Pozor: Bezpečnostní riziko",
29+
"note" : "Title shown in the browser window or tab when the current page may be a security risk due to phishing"
30+
},
2731
"malwarePageHeading" : {
2832
"title" : "Pozor: Tahle stránka může představovat{newline}bezpečnostní riziko",
2933
"note" : "Title shown in an error page that warn users of security risks on a website due to malware distribution. The {newline} tag should not be translated. It should be placed within the sentence to avoid having a single word hanging on the last line"
3034
},
31-
"malwareTabTitle" : {
32-
"title" : "Pozor: Bezpečnostní riziko",
33-
"note" : "Title shown in the browser window or tab when the current page may be a security risk due to malware"
34-
},
3535
"malwareWarningText" : {
3636
"title" : "Služba DuckDuckGo tuhle stránku zablokovala, protože může šířit malware, jehož cílem je narušit zabezpečení zařízení nebo odcizit osobní údaje.{newline}<a>Přečti si další informace.</a>",
3737
"note" : "Error description shown in an error page that warns users of security risks on a website due to malware distribution. The {newline} tag should not be translated. It should be placed before the translated <a>Learn More</a> text."
@@ -44,10 +44,6 @@
4444
"title" : "Pozor: Tahle stránka může představovat{newline}bezpečnostní riziko",
4545
"note" : "Title shown in an error page that warn users of security risks on a website due to Phishing issues. The {newline} tag should not be translated. It should be placed within the sentence to avoid having a single word hanging on the last line"
4646
},
47-
"phishingTabTitle" : {
48-
"title" : "Pozor: Bezpečnostní riziko",
49-
"note" : "Title shown in the browser window or tab when the current page may be a security risk due to phishing"
50-
},
5147
"phishingWarningText" : {
5248
"title" : "Tahle webová stránka se může vydávat za legitimní web, aby tě přiměla k poskytnutí osobních údajů, jako jsou hesla nebo čísla platebních karet.{newline}<a>Přečti si další informace.</a>",
5349
"note" : "Error description shown in an error page that warns users of security risks on a website due to Phishing issues. The {newline} tag should not be translated. It should be placed before the translated <a>Learn More</a> text."
@@ -56,6 +52,18 @@
5652
"title" : "Pokud věříš, že je tahle stránka bezpečná, můžeš <a>nahlásit chybu</a>. Můžeš taky stránku navštívit na vlastní nebezpečí.",
5753
"note" : "Title of the Advanced info section shown in an error page that warns users of security risks on a website due to malware distribution."
5854
},
55+
"scamPageHeading" : {
56+
"title" : "Pozor: Tahle stránka může představovat{newline}bezpečnostní riziko",
57+
"note" : "Title shown in an error page that warn users of security risks on a website due to suspected scam attempts. The {newline} tag should not be translated. It should be placed within the sentence to avoid having a single word hanging on the last line"
58+
},
59+
"scamWarningText" : {
60+
"title" : "Služba DuckDuckGo zablokovala tuto stránku, protože se tě může pokoušet pod falešnými záminkami přimět k převodu peněz, nákupu padělaného zboží nebo instalaci malwaru.{newline}<a>Další informace</a>",
61+
"note" : "Error description shown in an error page that warns users of security risks on a website due to suspected scam attempts. The {newline} tag should not be translated. It should be placed before the translated <a>Learn More</a> text."
62+
},
63+
"scamAdvancedInfoHeading" : {
64+
"title" : "Pokud věříš, že je tahle stránka bezpečná, můžeš <a>nahlásit chybu</a>. Můžeš taky stránku navštívit na vlastní nebezpečí.",
65+
"note" : "Title of the Advanced info section shown in an error page that warns users of security risks on a website due to suspected scam attempts."
66+
},
5967
"sslPageHeading" : {
6068
"title" : "Pozor: Tenhle web může být nezabezpečený",
6169
"note" : "Title shown in an error page that warn users of security risks on a website due to SSL issues"

0 commit comments

Comments
 (0)