mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
[PM-28950] Add enum normalizers to protect against corrupted user data in SDK mapping (#17723)
* Added normalizers to protect against corrpupted user data when mapping between client and SDK * Added comments * simplified secure note normalization
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { UriMatchType } from "@bitwarden/sdk-internal";
|
||||
|
||||
/*
|
||||
See full documentation at:
|
||||
https://bitwarden.com/help/uri-match-detection/#match-detection-options
|
||||
@@ -23,3 +25,28 @@ export type UriMatchStrategySetting = (typeof UriMatchStrategy)[keyof typeof Uri
|
||||
// using uniqueness properties of object shape over Set for ease of state storability
|
||||
export type NeverDomains = { [id: string]: null | { bannerIsDismissed?: boolean } };
|
||||
export type EquivalentDomains = string[][];
|
||||
|
||||
/**
|
||||
* Normalizes UriMatchStrategySetting for SDK mapping.
|
||||
* @param value - The URI match strategy from user data
|
||||
* @returns Valid UriMatchType or undefined if invalid
|
||||
*/
|
||||
export function normalizeUriMatchStrategyForSdk(
|
||||
value: UriMatchStrategySetting | undefined,
|
||||
): UriMatchType | undefined {
|
||||
if (value == null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
switch (value) {
|
||||
case 0: // Domain
|
||||
case 1: // Host
|
||||
case 2: // StartsWith
|
||||
case 3: // Exact
|
||||
case 4: // RegularExpression
|
||||
case 5: // Never
|
||||
return value;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user