Skip to content

Commit

Permalink
AG-33958 Show rules with $permissions modifier in the filtering log
Browse files Browse the repository at this point in the history
Merge in EXTENSIONS/browser-extension from feature/AG-33958 to v4.4

Squashed commit of the following:

commit b2b23e6
Author: scripthunter7 <d.tota@adguard.com>
Date:   Fri Jun 28 20:13:53 2024 +0200

    add to log store

commit 393fe7f
Merge: f606c6d af927a7
Author: scripthunter7 <d.tota@adguard.com>
Date:   Fri Jun 28 20:11:11 2024 +0200

    Merge branch 'v4.4' into feature/AG-33958

commit f606c6d
Author: scripthunter7 <d.tota@adguard.com>
Date:   Fri Jun 28 20:01:17 2024 +0200

    categorize permission rules

commit a312793
Author: scripthunter7 <d.tota@adguard.com>
Date:   Fri Jun 28 20:00:25 2024 +0200

    handle permissions rules at background
  • Loading branch information
scripthunter7 committed Jul 1, 2024
1 parent af927a7 commit 482ffda
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions Extension/src/background/api/filtering-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type FilteringEventRuleData = {
allowlistRule?: boolean,
allowlistStealthRule?: boolean,
cspRule?: boolean,
permissionsRule?: boolean,
modifierValue?: string,
cookieRule?: boolean,
contentRule?: boolean,
Expand Down
51 changes: 51 additions & 0 deletions Extension/src/background/services/filtering-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
StealthAllowlistActionEvent,
CspReportBlockedEvent,
getDomain,
ApplyPermissionsRuleEvent,
} from '@adguard/tswebextension';

import { messageHandler } from '../message-handler';
Expand Down Expand Up @@ -115,6 +116,11 @@ export class FilteringLogService {
FilteringLogService.onApplyCspRule,
);

defaultFilteringLog.addEventListener(
FilteringEventType.ApplyPermissionsRule,
FilteringLogService.onApplyPermissionsRule,
);

defaultFilteringLog.addEventListener(
FilteringEventType.ApplyCosmeticRule,
FilteringLogService.onApplyCosmeticRule,
Expand Down Expand Up @@ -288,6 +294,51 @@ export class FilteringLogService {
}
}

/**
* Records the application of the rule with $permissions modifier.
*
* @param ruleEvent Item of {@link ApplyPermissionsRuleEvent}.
* @param ruleEvent.data Data for this event.
*/
private static async onApplyPermissionsRule({ data }: ApplyPermissionsRuleEvent): Promise<void> {
const {
tabId,
filterId,
ruleIndex,
isAllowlist,
isImportant,
isDocumentLevel,
isCsp,
isCookie,
advancedModifier,
frameDomain,
...eventData
} = data;

filteringLogApi.addEventData(tabId, {
...eventData,
// TODO: Fix `string | null` vs `string | undefined` inconsistency
frameDomain: frameDomain ?? undefined,
requestDomain: getDomain(eventData.requestUrl) ?? undefined,
requestRule: {
filterId,
ruleIndex,
allowlistRule: isAllowlist,
isImportant,
documentLevelRule: isDocumentLevel,
isStealthModeRule: filterId === AntiBannerFiltersId.StealthModeFilterId,
cspRule: isCsp,
permissionsRule: true,
cookieRule: isCookie,
modifierValue: advancedModifier ?? undefined,
},
});

if (!SettingsApi.getSetting(SettingOption.DisableCollectHits)) {
HitStatsApi.addRuleHit(filterId, ruleIndex);
}
}

/**
* Records the application of the rule with $removeparam modifier.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ export const getRequestEventType = (event) => {
return 'WebRTC';
case RequestType.Csp:
return 'CSP';
case RequestType.PermissionsPolicy:
return 'Permissions Policy';
case RequestType.CspReport:
return 'CSP report';
case RequestType.Cookie:
Expand Down
3 changes: 2 additions & 1 deletion Extension/src/pages/filtering-log/filteringLogStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const getStatusMode = (event) => {
scriptRule,
cookieRule,
cspRule,
permissionsRule,
} = requestRule;

if (allowlistRule) {
Expand All @@ -89,7 +90,7 @@ export const getStatusMode = (event) => {
} else {
mode = StatusMode.BLOCKED;
}
} else if (cspRule) {
} else if (cspRule || permissionsRule) {
mode = StatusMode.MODIFIED;
} else {
mode = StatusMode.BLOCKED;
Expand Down
2 changes: 2 additions & 0 deletions Extension/src/pages/filtering-log/stores/LogStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ const initEventTypesFilters = {
RequestType.Font,
RequestType.Websocket,
RequestType.Csp,
RequestType.PermissionsPolicy,
RequestType.Cookie,
RequestType.Ping,
RequestType.WebRTC,
Expand Down Expand Up @@ -429,6 +430,7 @@ class LogStore {
|| filteringEvent.requestRule?.cssRule
|| filteringEvent.requestRule?.scriptRule
|| filteringEvent.requestRule?.cspRule
|| filteringEvent.requestRule?.permissionsRule
|| filteringEvent.replaceRules
|| filteringEvent.removeParam
|| filteringEvent.removeHeader);
Expand Down

0 comments on commit 482ffda

Please sign in to comment.