Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malicious website protection - Android support #300

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions integration-tests/android.spec-int.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,56 @@ test.describe('Protections toggle', () => {
toggleFlows((page) => DashboardPage.android(page));
});

test.describe('phishing & malware protection', () => {
test('phishing warning', { tag: '@screenshots' }, async ({ page }) => {
/** @type {DashboardPage} */
const dash = await DashboardPage.android(page);
await dash.addState([testDataStates.phishing]);
await dash.screenshot('phishing-warning.png');
await dash.hasPhishingIcon();
await dash.hasPhishingHeadingText();
await dash.hasPhishingWarningText();
await dash.hasPhishingStatusText();
await dash.connectionLinkDoesntShow();
});

test('malware warning', { tag: '@screenshots' }, async ({ page }) => {
/** @type {DashboardPage} */
const dash = await DashboardPage.android(page);
await dash.addState([testDataStates.malware]);
await dash.screenshot('malware-warning.png');
await dash.hasMalwareIcon();
await dash.hasMalwareHeadingText();
await dash.hasMalwareWarningText();
await dash.hasMalwareStatusText();
await dash.connectionLinkDoesntShow();
});

test('shows report as safe link', async ({ page }) => {
/** @type {DashboardPage} */
const dash = await DashboardPage.android(page);
await dash.addState([testDataStates.malware]);
await dash.clickReportAsSafeLink();
await dash.mocks.calledForReportAsSafeLink('https://privacy-test-pages.site/security/badware/malware.html');
});

test('shows malware help page link', async ({ page }) => {
/** @type {DashboardPage} */
const dash = await DashboardPage.android(page);
await dash.addState([testDataStates.malware]);
await dash.clickMalwareHelpPageLink();
await dash.mocks.calledForHelpPagesLink();
});

test('shows phishing help page link', async ({ page }) => {
/** @type {DashboardPage} */
const dash = await DashboardPage.android(page);
await dash.addState([testDataStates.phishing]);
await dash.clickPhishingHelpPageLink();
await dash.mocks.calledForHelpPagesLink();
});
});

test.describe('breakage form', () => {
test('sends message when breakage form is triggered from primary screen', async ({ page }) => {
/** @type {DashboardPage} */
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 30 additions & 1 deletion shared/js/browser/android-communication.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import {
cookiePromptManagementStatusSchema,
localeSettingsSchema,
maliciousSiteStatusSchema,
protectionsStatusSchema,
remoteFeatureSettingsSchema,
requestDataSchema,
Expand Down Expand Up @@ -48,6 +49,9 @@ let isPendingUpdates;
let parentEntity;
const cookiePromptManagementStatus = {};

/** @type {import('../../../schema/__generated__/schema.types').MaliciousSiteStatus} */
let maliciousSiteStatus;

/** @type {string | undefined} */
let locale;

Expand All @@ -58,6 +62,7 @@ const combineSources = () => ({
tab: Object.assign(
{},
trackerBlockingData || {},
{ maliciousSiteStatus: maliciousSiteStatus ?? null },
{
isPendingUpdates,
parentEntity,
Expand All @@ -75,7 +80,8 @@ const resolveInitialRender = function () {
const isIsProtectedSet = typeof protections !== 'undefined';
const isTrackerBlockingDataSet = typeof trackerBlockingData === 'object';
const isLocaleSet = typeof locale === 'string';
if (!isLocaleSet || !isUpgradedHttpsSet || !isIsProtectedSet || !isTrackerBlockingDataSet) {
const isMaliciousSiteSet = maliciousSiteStatus && maliciousSiteStatus.kind !== undefined;
if (!isLocaleSet || !isUpgradedHttpsSet || !isIsProtectedSet || !isTrackerBlockingDataSet || !isMaliciousSiteSet) {
return;
}

Expand Down Expand Up @@ -179,6 +185,28 @@ export function onChangeLocale(payload) {
channel?.send('updateTabData', { via: 'onChangeLocale' });
}

/**
* {@inheritDoc common.onChangeMaliciousSiteStatus}
* @type {import("./common.js").onChangeMaliciousSiteStatus}
* @group macOS -> JavaScript Interface
* @example
*
* ```kotlin
* // kotlin
* webView.evaluateJavascript("javascript:onChangeMaliciousSiteStatus(${maliciousSiteStatusJsonString});", null)
* ```
*/
export function onChangeMaliciousSiteStatus(payload) {
const parsed = maliciousSiteStatusSchema.safeParse(payload);
if (!parsed.success) {
console.error('could not parse incoming data from onChangeMaliciousSiteStatus');
console.error(parsed.error);
return;
}
maliciousSiteStatus = parsed.data;
resolveInitialRender();
}

/**
* {@inheritDoc common.onChangeFeatureSettings}
* @type {import("./common.js").onChangeFeatureSettings}
Expand Down Expand Up @@ -493,6 +521,7 @@ export function setup(debug) {
};
window.onChangeProtectionStatus = onChangeProtectionStatus;
window.onChangeLocale = onChangeLocale;
window.onChangeMaliciousSiteStatus = onChangeMaliciousSiteStatus;
window.onChangeRequestData = onChangeRequestData;
window.onChangeConsentManaged = onChangeConsentManaged;
window.onChangeFeatureSettings = onChangeFeatureSettings;
Expand Down
2 changes: 1 addition & 1 deletion shared/js/browser/macos-communication.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const combineSources = () => ({
tab: Object.assign(
{},
trackerBlockingData || {},
{ maliciousSiteStatus: maliciousSiteStatus ?? false },
{ maliciousSiteStatus: maliciousSiteStatus ?? null },
mgurgel marked this conversation as resolved.
Show resolved Hide resolved
{
isPendingUpdates,
parentEntity,
Expand Down
3 changes: 2 additions & 1 deletion shared/js/browser/utils/communication-mocks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export async function mockDataProvider(params) {
window.onChangeLocale?.(state.localeSettings);
window.onChangeRequestData(state.url, { requests: state.requests || [] });

if (platform?.name === 'macos' || platform?.name === 'ios') {
if (platform?.name === 'macos' || platform?.name === 'ios' || platform?.name === 'android') {
console.log('HERE');
mgurgel marked this conversation as resolved.
Show resolved Hide resolved
window.onChangeMaliciousSiteStatus?.(state.maliciousSiteStatus);
}
}
Expand Down
2 changes: 1 addition & 1 deletion shared/js/ui/platform-features.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function createPlatformFeatures(platform) {
initialScreen: screen,
opener,
supportsInvalidCertsImplicitly: platform.name !== 'browser' && platform.name !== 'windows',
supportsMaliciousSiteWarning: platform.name === 'macos' || platform.name === 'ios',
supportsMaliciousSiteWarning: platform.name === 'macos' || platform.name === 'ios' || platform.name === 'android',
includeToggleOnBreakageForm,
randomisedCategories,
});
Expand Down