Struct adblock::resources::PermissionMask

source ·
pub struct PermissionMask(/* private fields */);
Expand description

Specifies a set of permissions required to inject a scriptlet resource.

Permissions can be specified when parsing individual lists using crate::FilterSet in order to propagate the permission level to all filters contained in the list.

In practice, permissions are used to limit the risk of third-party lists having access to powerful scriptlets like uBlock Origin’s trusted-set-cookie, which has the ability to set arbitrary cookies to arbitrary values on visited sites.

§Example

const COOKIE_ACCESS: PermissionMask = PermissionMask::from_bits(0b00000001);
const LOCALSTORAGE_ACCESS: PermissionMask = PermissionMask::from_bits(0b00000010);

// `untrusted_filters` will not be able to use privileged scriptlet injections.
filter_set.add_filters(
    untrusted_filters,
    Default::default(),
);
// `trusted_filters` will be able to inject scriptlets requiring `COOKIE_ACCESS`
// permissions or `LOCALSTORAGE_ACCESS` permissions.
filter_set.add_filters(
    trusted_filters,
    ParseOptions {
        permissions: COOKIE_ACCESS | LOCALSTORAGE_ACCESS,
        ..Default::default()
    },
);

let mut engine = Engine::from_filter_set(filter_set, true);
// The `trusted-set-cookie` scriptlet cannot be injected without `COOKIE_ACCESS`
// permission.
engine.add_resource(Resource {
    name: "trusted-set-cookie.js".to_string(),
    aliases: vec![],
    kind: ResourceType::Mime(MimeType::ApplicationJavascript),
    content: base64::encode("document.cookie = '...';"),
    dependencies: vec![],
    permission: COOKIE_ACCESS,
});

Implementations§

source§

impl PermissionMask

source

pub const fn from_bits(bits: u8) -> Self

Construct a new PermissionMask with the given bitmask. Use PermissionMask::default() instead if you don’t want to restrict or grant any permissions.

source

pub fn is_injectable_by(&self, filter_mask: PermissionMask) -> bool

Can filter_mask authorize injecting a resource requiring self permissions?

Trait Implementations§

source§

impl BitOr for PermissionMask

§

type Output = PermissionMask

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: PermissionMask) -> Self::Output

Performs the | operation. Read more
source§

impl BitOrAssign for PermissionMask

source§

fn bitor_assign(&mut self, rhs: PermissionMask)

Performs the |= operation. Read more
source§

impl Clone for PermissionMask

source§

fn clone(&self) -> PermissionMask

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PermissionMask

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for PermissionMask

source§

fn default() -> PermissionMask

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for PermissionMask

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for PermissionMask

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for PermissionMask

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,