pub trait IntoUntrustedVariant<OtherInsecure> {
// Required method
fn to_untrusted_variant(self) -> OtherInsecure;
}
Expand description
This trait provides a way to convert an untrusted or trusted type to another untrusted type.
This trait MUST guarantee the following properties:
- The conversion result MUST NOT contain untainted data that was tainted in the input.
- The conversion MUST NOT do any sanitization.
- If the input is not tainted, all parts of the output MUST be tainted.
If you could not guarantee 1-3, then you MUST NOT implement this trait. Probably you meant to
implement SanitizeWith
or SanitizeValue
instead, which allow you to sanitize the data or remove taint.
This trait is mainly used to map UntrustedValue<SomeStruct>
to a struct where all members are
wrapped inside UntrustedValue
containers amd vice-versa.
This trait is auto-implemented by the #[derive(UntrustedVariant)]
macro, which will turn
an instance of a struct like this:
#[derive(UntrustedVariant)]
pub struct Example {
pub name: String,
}
into an instance of:
pub struct ExampleUntrusted {
pub name: UntrustedValue<String>,
}
More on the guaranteed properties:
- All data parts in the input that were annotated as
UntrustedValue
must be dropped in the output or somehow again wrapped in aUntrustedValue
container. For example, when implementing this trait forUntrustedValue<Example>
property (1) is conserved since the membername
is wrapped in anUntrustedValue
container. Dropping parts of the input is allowed since this means that the data can not be used in an untrusted manner anymore. - This constraint is placed upon the user of this trait to make security analysis of the code easier. Analysing the
sanitization process is in that sense easier because analysts can focus analysing the implementations of
SanitizeWith
andSanitizeValue
that are designated for sanitization. - If the input is not tainted, hence implementing this trait for a trusted type (e.g. the
Example
struct), the input should be regarded the same as in property (1). This means implementing this trait forUntrustedValue<Example>
orExample
should yield the same result. This constraint is placed upon the user of this trait since crates providing Serialize/Deserialize features (like Serde) will likely operate on trusted types (e.g.Example
). Using theÌntoUntrustedVariant
trait is therefore the shortcut to first wrap the trusted type inUntrustedValue
and then callingIntoUntrustedVariant
on it.
Required Methods§
Sourcefn to_untrusted_variant(self) -> OtherInsecure
fn to_untrusted_variant(self) -> OtherInsecure
Returns an equivalent untrusted type.
No sanitization is done here, only the conversion to an untrusted type.
This function MUST guarantee the following properties:
- The conversion result MUST NOT contain untainted data that was tainted in the input.
- The conversion MUST NOT do any sanitization.
- If the input is not tainted, all parts of the output MUST be tainted.