Skip to main content

UntrustedValue

Struct UntrustedValue 

Source
pub struct UntrustedValue<Insecure> { /* private fields */ }
Expand description

Represents an untrusted/untrustworthy value. The data contained inside this type is called tainted.

An attacker might be able to control (part) of the returned value. Take special care processing this data.

Taint can be cleared by using one of the traits SanitizeWith or SanitizeValue. Effectively, sanitizing the data.

This type does explicitly not implement common traits like Debug, Display, etc. since the data contained is considered untrusted. If desired you COULD implement these traits in for your custom types.

For naming purposes an untrusted value mapped inside this type is considered safe/trusted since it can not be accessed without sanitization.

Implementations§

Source§

impl<Insecure> UntrustedValue<Insecure>

Implementation of the UntrustedValue type.

Source

pub fn use_untrusted_value(self) -> Insecure

Be sure that you carefully handle the returned value since it may be controllable by a malicious actor.

Does not perform any sanitization on the returned value.

Examples found in repository?
examples/untrusted_inputs_nested_structs.rs (line 35)
33    fn sanitize_value(self) -> Result<NetworkConfig, Self::Error> {
34        Ok(NetworkConfig {
35            port: self.port.use_untrusted_value(),
36            listen_address: self.listen_address.use_untrusted_value(),
37        }) // in real application: do some sanitizing
38    }
Source

pub fn wrap(value: Insecure) -> Self

Wraps the provided value as UntrustedValue

Examples found in repository?
examples/untrusted_outputs.rs (line 18)
14fn main() {
15    // call library function
16    assert_eq!(
17        some_lib_func().type_id(),
18        UntrustedValue::wrap("test".to_string()).type_id()
19    );
20}

Trait Implementations§

Source§

impl<Insecure: Clone> Clone for UntrustedValue<Insecure>

A tainted value may be cloned if the underlying value is cloneable. This is considered safe since the taint is also cloned.

Source§

fn clone(&self) -> Self

Clones the value

1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Insecure: Copy> Copy for UntrustedValue<Insecure>

Source§

impl<Insecure> From<Insecure> for UntrustedValue<Insecure>

Provide easy conversion from some value to an UntrustedValue.

Source§

fn from(value: Insecure) -> Self

Wraps the provided value as UntrustedValue

Source§

impl<Insecure, Trusted> From<UntrustedValue<Insecure>> for MaybeUntrusted<Insecure, Trusted>

Source§

fn from(value: UntrustedValue<Insecure>) -> Self

Converts an UntrustedValue to a MaybeUntrusted value

Source§

impl<Sanitized, E, Insecure: SanitizeValue<Sanitized, Error = E>> SanitizeValue<Sanitized> for UntrustedValue<Insecure>

If the tainted data type can be sanitized using the SanitizeValue trait, implement also the SanitizeValue trait for this UntrustedValue type.

Source§

type Error = E

The error type will be propagated from the underlying SanitizeValue implementation.

Source§

fn sanitize_value(self) -> Result<Sanitized, Self::Error>

Sanitizes the value.

The returned value is sanitized and can be safely used. If the value cannot be sanitized, an error must be returned.

Source§

impl<Insecure, Trusted> SanitizeWith<Insecure, Trusted> for UntrustedValue<Insecure>

Taint can be cleared from the value by using a sanitizer. Effectively unpacking the value; passing it to the sanitizer and returning the result.

Source§

fn sanitize_with<Sanitizer, Error>( self, sanitizer: Sanitizer, ) -> Result<Trusted, Error>
where Sanitizer: FnOnce(Insecure) -> Result<Trusted, Error>,

Sanitizes the value using the provided sanitizer.

The sanitizer may transmute the value to a different type. If sanitization fails, an error must be returned.

Auto Trait Implementations§

§

impl<Insecure> Freeze for UntrustedValue<Insecure>
where Insecure: Freeze,

§

impl<Insecure> RefUnwindSafe for UntrustedValue<Insecure>
where Insecure: RefUnwindSafe,

§

impl<Insecure> Send for UntrustedValue<Insecure>
where Insecure: Send,

§

impl<Insecure> Sync for UntrustedValue<Insecure>
where Insecure: Sync,

§

impl<Insecure> Unpin for UntrustedValue<Insecure>
where Insecure: Unpin,

§

impl<Insecure> UnsafeUnpin for UntrustedValue<Insecure>
where Insecure: UnsafeUnpin,

§

impl<Insecure> UnwindSafe for UntrustedValue<Insecure>
where Insecure: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<Insecure, OtherInsecure> FromTrustedVariant<OtherInsecure> for Insecure
where OtherInsecure: IntoUntrustedVariant<Insecure>,

Source§

fn from_untrusted_variant(other: OtherInsecure) -> Insecure

Converts the provided type to an equivalent untrusted type.

No sanitization is done here, only the conversion to an untrusted type.

This function MUST guarantee the following properties:

  1. The conversion result MUST NOT contain untainted data that was tainted in the input.
  2. The conversion MUST NOT do any sanitization.
  3. If the input is not tainted, all parts of the output MUST be tainted.

This method is auto-implemented since the other type implements the IntoUntrustedVariant trait.

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,

Source§

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>,

Source§

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>,

Source§

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.