Skip to content
Tyler Kendrick edited this page May 27, 2019 · 8 revisions

Welcome to the Hygiene wiki!

What is Hygiene?

If you're asking this question, then I guarantee that you're in need of it!

noun: hygiene conditions or practices conducive to maintaining health and preventing disease, especially through cleanliness.

Hygiene for .NET is a library meant to keep your code, data, and inputs clean and sanitary. By formalizing and outlining the good habits for sanitization, this project seeks to assist developers in writing more resilient, maintainable code.

Identifying and cleaning smelly code.

Anytime code crosses an integration point, control over the data passing through your system is lost to another consumer. In order to ensure that data conforms to the system's expectations, it is necessary to validate data and make attempts to normalize that data to the supported formats.

Improper cleaning and its consequences.

Refusing to clean your inputs means that you can open your system to potential vulnerabilities. However, being overzealous with your cleaning habits may lead to your system supporting too broad a set of data. For example, trimming whitespace from a credit card number means that consumers of your service will be able to expect arbitrary whitespace at the end of a card number as valid input, and may become a "hidden feature" requiring support into the future. Consciously consider the constraints that make your data valid, and what needs to be cleaned will become clear.

Provided Sanitizers.

String Sanitizer

    var configuration = new SanitizerConfigurationProvider(builder
        => builder.ForType((ref string input)
            => input = input.Trim('-')));

    var sanitizer = configuration.CreateSanitizer<string>();

Supplements to better disinfect your code.