When it comes to application security, one might often wonder, "Where should I position my controls?". It's a valid question, and its answer plays a significant role in the effectiveness of security measures.
Let's examine a few scenarios:
Where should these controls be situated?
A simple yet effective guideline to remember is: Place your controls as close as possible to what you're safeguarding.
For instance, when ensuring the uniqueness of email addresses during user registration, the most effective place for these controls is directly within the database. Why?
Avoiding such duplications is essential. Otherwise, one lands in the tedious situation of keeping controls in sync across applications, accumulating unnecessary technical debt.
Similarly, when countering IDOR, the control should be adjacent to the data, typically in the microservice accessing it.
While it might seem enticing to use an API Gateway, it's far from the data and might not be the best solution. Why?
Yes, there's room for controls that act early, such as when no authentication is evident. And API Gateways can be useful for immediate patching. However, these shouldn't be the foundation of one's security strategy.
Whether the task is email validation or preventing IDOR, the principle remains: Keep controls close to the data they protect. This strategy enhances their effectiveness, curtails technical debt, and bolsters a genuine security culture within teams.