I'm familiar with the use of the context object design pattern - a lightweight context wrapper around objects passed between tiers.
If one were to use the context object to track taint (untrusted user input), or the origin tier, I could see how a receiving tier could dynamically filter, encode, or validate accordingly.
For example: A user sends "HTTP/HTML" context data which will eventually be stored as a file on the system. The file save method could detect the context and decode HTML entities, assign a random identifier to the file upload, and associate the user action and the file-name in the database.
My question is: how is that any smarter than applying all filtering, encoding and validation by default? What cases exist where knowing the origin context improves security beyond just good input validation/encoding?
I'm working in Java/J2EE/Struts but this is generalizable to other languages and frameworks.
References:
http://www.corej2eepatterns.com/Patterns2ndEd/ContextObject.htm
http://www.cs.wustl.edu/~schmidt/PDF/Context-Object-Pattern.pdf
http://www.owasp.org/index.php/Category:OWASP_Security_Analysis_of_Core_J2EE_Design_Patterns_Project
With my thanks,
-Ben