Let’s get right to it:
🗣️ Never write your own authorization code. Just don’t
You’ve probably done it. We all have. That innocent-looking if statement checking user roles:
func myApi() {
roles := fetch_roles_for(request.user)
if "admin" in roles || "editor" in roles {
approve()
}
}
It feels fine… until six months later, you’re drowning in permission bugs, scrambling to debug why Bob from Finance can edit your production database. Sound familiar?
Let’s unpack why this happens—and why you should stop before writing another line of custom AuthZ code.
🧠 Code Is Debt, Especially AuthZ Code
Every line of authorization code you write is debt:
- It must be tested.
- It must be maintained.
- It must be reviewed and secured.
AuthZ bugs are security bugs. One wrong if
statement, and your customer’s sensitive data leaks. Good luck explaining that breach to your CISO or customers. Just look at the number of recent data breaches that have occurred thanks to broken access control.
🔄 Hard to Evolve
Here’s a scenario:
Your simple role checks work until your CTO suddenly says,
"We need fine-grained access control for every document by next quarter."
Now your tidy if role == 'admin'
logic needs to handle document-level permissions, delegation, and auditing. You’re staring at your old code thinking: "How did we get here?”
Even worse if you’re a polyglot shop: you now need to replicate your homegrown logic across Go, Node.js, Python, and Java… or expose it as an RPC service and accidentally create a distributed dependency nightmare.
📉 Role-Based Agony (RBAC Explosion)
Role-Based Access Control (RBAC) always starts simple:
- Admin
- Editor
- Viewer
Then marketing wants a custom dashboard.
Finance wants read-only access to sales data.
Support needs limited write access to customer records.
Before long you’ve got 50+ roles hardcoded across endpoints and environments. Want to change one? Enjoy your week-long deploy cycle and pray nothing breaks.
🧍 Authorization Is a Human Problem, Too
Here’s the thing:
Who decides access?
Well typically that is done on the Business side of things - HR, InfoSec, People Managers and the like.
Who implements it?
You, the engineer.
When these two worlds drift apart, your authorization logic becomes a graveyard of outdated roles, guesswork, and subtle bugs nobody understands.
Your codebase reflects services, modules, endpoints.
Your access model reflects teams, departments, projects. Trying to map one to the other is a recipe for friction—and failure.
🚨 Distributed Mess
In a distributed system, your goal is simple: make many computers behave like one computer. But when every service embeds its own ad-hoc AuthZ logic, subtle differences creep in:
- Marketing thinks they have access.
- Engineering says otherwise.
Your access control looks like spaghetti… but distributed spaghetti.
🔬 You’re Not an Authorization Expert
Let’s be blunt:
You wouldn’t write your own database, would you? (Please say no.)
Authorization research is as old as database research. Why reinvent the wheel on one of your application’s most critical paths?
⚙️ AuthZ Must Perform at Scale
Authorization isn’t just about correctness, it’s also about performance. After all permission checks are on the critical path.
- Fast checks at low latency.
- Always available.
- Resilient under load.
This isn’t something you hack together in a sprint. It’s infrastructure-grade engineering that involves thinking about caching, distributed consistency, failover, and observability.
Why This Matters Now?
Sure, maybe a few years ago you could “get away with it.” But today’s requirements demand:
✅ Fine-grained permissions
✅ Microservices architectures
✅ Global scale
✅ Collaborative apps with dynamic access policies
That dials up the complexity all the way up to 11.
And the stakes are higher:
OWASP’s current Top 10 security risks for web apps puts Broken Access Control at #1 but it doesn't have to be.
Don't believe me? Here's an example from the industry:
In the 2010s, Broken Authentication was consistently in the Top 3 in OWASP's lists¹. So as an industry we:
✅ Stopped writing our own authentication
✅ Adopted off-the-shelf identity providers
Result?
The latest OWASP list puts 'Identification and Authentication Failures' all the way down at #7
It’s time we do the same for authorization.
The Better Way: Centralized Authorization
The good news? You have options:
OWASP themselves recommend adopting modern models like ABAC (Attribute-Based Access Control) or ReBAC (Relationship-Based Access Control) to fix broken access control.
Using centralized, open source AuthZ systems (such as SpiceDB, inspired by Google Zanzibar) offer:
- Fine-grained checks
- Fast, low-latency queries
- Clear separation of business logic and access policy
In short: let experts design, build, and maintain the thing that keeps your user data secure—so you can focus on building your product.
🔔 Final word
Before I get flamed in the comments, here's a disclaimer:
If you’re writing a weekend hobby app, maybe a simple if role == admin
is fine.
If you’re scaling a business or product, you can’t afford to wing it anymore.
Remember:
“Just because you can write your own AuthZ doesn’t mean you should.”
Got a custom AuthZ horror story? Share it in the comments 👉
[1]Broken Authentication was #2 in 2017, #2 in 2013, #3 in 2010
(source)
Top comments (0)