Click here to Skip to main content
15,891,777 members
Articles / Programming Languages / Ruby

A Simple Taint Checking Solution for C#

Rate me:
Please Sign up or sign in to vote.
4.91/5 (13 votes)
16 Mar 2011CPOL12 min read 52.5K   513   23  
We propose a way to secure C# programs by emulating Taint checking
namespace TaintChecking
{
    public class Tainted<T>
    {
        private bool _tainted;
        private T _target;

        public delegate bool IsCleanUntaintTreatmentMethod(T taintedObject);

        public Tainted(T target)
        {
            _tainted = true;
            _target = target;
        }

        public bool IsTainted
        {
            get { return _tainted; }
        }

        public bool IsClean
        {
            get { return !this.IsTainted; }
        }

        public T Target
        {
            get
            {
                if(this.IsTainted)
                {
                    throw new TaintException();
                }
            
                return _target;
            }
        }

        public void Taint()
        {
            _tainted = true;
        }

        public void Untaint(IsCleanUntaintTreatmentMethod treatmentMethod)
        {
            _tainted = !treatmentMethod(_target);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Canada Canada
Paul Lessard has received a MSc in computer science and a BASc in computer science and software engineering. He is currently employed as a software developer and junior architect.

Comments and Discussions