pub struct ShellCommandLimitedDoubleQuotesSanitizer {
    template: String,
    string_to_echo: String,
    string_to_execute: String,
}
Expand description

Shell command builder with simple but limited sanitizer

The limited sanitization will panic if the value contains double quotes. Command injections attack is possible because the shell command mixes executable code and data in a single string. The attacker could format the “user input” data in a way that it transforms it into “executable code”. A true sanitization is hard to do in software. It would mean to understand all the intricacies of bash syntax?! Another solution is to create a complex object model to have every command and data separated. Too complicated and developer unfriendly. Instead here we take that the developer is a trusted person and he knows how to create the template correctly, so that the placeholders are always de-facto delimited with double-quote inside the shell command. This avoids the problem of injection of any other symbol except double-quotes. The injection of double quote would finish the double-quote data and open the door tho write executable code. It would be very complicated to check if “escaped double quotes” are or not correct in the context of the template. So I don’t allow them at all. This covers the vast majority of simple use cases. Placeholders are delimited with curly brackets. Shell command builder with simple but limited sanitizer

The limited sanitization will panic if the value contains double quotes. Command injections attack is possible because the shell command mixes executable code and data in a single string. The attacker could format the “user input” data in a way that it transforms it into “executable code”. A true sanitization is hard to do in software. It would mean to understand all the intricacies of bash syntax?! Another solution is to create a complex object model to have every command and data separated. Too complicated and developer unfriendly. Instead here we take that the developer is a trusted person and he knows how to create the template correctly, so that the placeholders are always de-facto delimited with double-quote inside the shell command. This avoids the problem of injection of any other symbol except double-quotes. The injection of double quote would finish the double-quote data and open the door tho write executable code. It would be very complicated to check if “escaped double quotes” are or not correct in the context of the template. So I don’t allow them at all. This covers the vast majority of simple use cases. Placeholders are delimited with curly brackets.

Fields§

§template: String§string_to_echo: String§string_to_execute: String

Trait Implementations§

source§

impl ShellCommandLimitedDoubleQuotesSanitizerTrait for ShellCommandLimitedDoubleQuotesSanitizer

source§

fn new(template: &str) -> ResultWithLibError<Self>

Template for the shell command with placeholders

The limited sanitization will panic if the value contains double quotes. Placeholders are delimited with curly brackets. The developer must be super careful to write the template correctly. The placeholders must be inside a block delimited with double quotes. In a way that only an injection of a double quote can cause problems. There is no software check of the correctness of the template.

source§

fn arg( &mut self, placeholder: &str, value: &str ) -> ResultWithLibError<&mut Self>

Replace placeholders with the value

The limited sanitization will panic if the value contains double quotes. Enter the placeholder parameter delimited with curly brackets. It would be very complicated to check if “escaped double quotes” are or not correct in the context of the template. So I don’t allow them at all. This covers the vast majority of simple use cases.

source§

fn arg_secret( &mut self, placeholder: &str, value: &SecretString ) -> ResultWithLibError<&mut Self>

Just like arg(), but for secrets that must be not echoed on the screen

source§

fn run(&self) -> ResultWithLibError<()>

Run the sanitized command with no additional checks

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>

where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more