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
});
Loading
Loading
Loading

0 commit comments

Comments
 (0)