Broken Access Control in Fiber
How Broken Access Control Manifests in Fiber
Broken Access Control in Fiber applications typically emerges through several attack vectors that exploit the framework's routing and middleware architecture. The most common pattern involves IDOR (Insecure Direct Object Reference) vulnerabilities where endpoints expose resource identifiers without proper authorization checks.
Consider a typical Fiber REST API handling user resources:
app := fiber.New()
// Vulnerable: No authorization check
app.Get("/api/users/:id", func(c *fiber.Ctx) error {
id := c.Params("id")
user, err := db.GetUserByID(id)
if err != nil {
return c.Status(404).SendString("Not Found")
}
return c.JSON(user)
})
This endpoint allows any authenticated user to retrieve any other user's data simply by changing the ID parameter. The vulnerability stems from missing authorization logic that should verify the requesting user has permission to access the requested resource.
Another common manifestation occurs with privilege escalation through improper role validation. Fiber applications often implement role-based access control (RBAC) but fail to validate permissions correctly:
app := fiber.New()
// Vulnerable: Role check is bypassed
app.Post("/api/admin/delete-user", func(c *fiber.Ctx) error {
if c.Locals("role") == "admin" { // This check can be bypassed
id := c.FormValue("user_id")
db.DeleteUser(id)
return c.SendString("User deleted")
}
return c.Status(403).SendString("Forbidden")
})
The vulnerability here is that the role check relies on client-controlled data or isn't properly enforced across all execution paths. An attacker could manipulate the request to bypass this check entirely.
Property-level authorization failures represent another Fiber-specific pattern. When returning structured data, applications often expose sensitive fields to unauthorized users:
app := fiber.New()
// Vulnerable: Exposes sensitive user data
app.Get("/api/user/profile", func(c *fiber.Ctx) error {
user := c.Locals("user").(*User)
return c.JSON(user) // Exposes email, phone, SSN to anyone
})
Without filtering sensitive properties based on the requesting user's relationship to the resource, this endpoint leaks private information to any authenticated user.
Fiber-Specific Detection
Detecting Broken Access Control in Fiber applications requires both static code analysis and dynamic testing approaches. The framework's middleware architecture provides natural interception points for security scanning.
Static analysis should focus on identifying authorization gaps in route handlers. Look for patterns where:
- Resource identifiers appear in URL parameters without authorization checks
- Database queries execute without verifying user permissions
- Role-based checks exist but aren't comprehensive across all code paths
- Sensitive data structures are returned without field filtering
Dynamic testing with middleBrick reveals runtime access control failures through black-box scanning. The scanner automatically tests for IDOR vulnerabilities by:
- Identifying endpoints with numeric or UUID parameters
- Modifying parameter values to access other users' resources
- Checking if authorization failures return different HTTP status codes
- Analyzing response payloads for sensitive data exposure
For example, middleBrick would detect the IDOR vulnerability in this endpoint:
app.Get("/api/orders/:id", func(c *fiber.Ctx) error {
id := c.Params("id")
order, err := db.GetOrder(id) // No user ownership check
if err != nil {
return c.Status(404).SendString("Not Found")
}
return c.JSON(order)
})
The scanner would test by requesting different order IDs and verifying whether users can access orders belonging to others. It would flag this as a critical BOLA (Broken Object Level Authorization) vulnerability.
middleBrick's Fiber-specific detection also includes checking for:
- Missing authentication middleware on sensitive endpoints
- Inconsistent authorization logic across similar endpoints
- Exposure of internal identifiers (database IDs, UUIDs) that enable enumeration attacks
- Insufficient rate limiting on authentication and authorization endpoints
Fiber-Specific Remediation
Fixing Broken Access Control in Fiber requires implementing proper authorization checks using the framework's middleware system and context management features. The most effective approach uses a centralized authorization middleware.
First, implement a permission-checking middleware that validates user access rights:
type Permission string
const (
PermissionReadUser Permission = "read:user"
PermissionWriteUser Permission = "write:user"
PermissionAdmin Permission = "admin"
)
func Authorize(permission Permission) fiber.Handler {
return func(c *fiber.Ctx) error {
user := c.Locals("user").(*User)
if !user.HasPermission(permission) {
return c.Status(403).SendString("Forbidden")
}
return c.Next()
}
}
// Apply to routes
app.Get("/api/users/:id", Authorize(PermissionReadUser), func(c *fiber.Ctx) error {
id := c.Params("id")
if id != c.Locals("user").(*User).ID {
return c.Status(403).SendString("Forbidden")
}
user, err := db.GetUserByID(id)
if err != nil {
return c.Status(404).SendString("Not Found")
}
return c.JSON(user)
})
This pattern ensures every request passes through authorization validation before accessing sensitive resources.
For property-level authorization, implement response filtering to prevent data exposure:
type UserResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email,omitempty"`
CreatedAt string `json:"created_at"`
}
func (u *User) ToResponse(forUser *User) *UserResponse {
resp := &UserResponse{
ID: u.ID,
Name: u.Name,
CreatedAt: u.CreatedAt,
}
// Only show email if same user or admin
if forUser.ID == u.ID || forUser.HasPermission(PermissionAdmin) {
resp.Email = u.Email
}
return resp
}
// Usage in handler
app.Get("/api/users/:id", func(c *fiber.Ctx) error {
id := c.Params("id")
currentUser := c.Locals("user").(*User)
if id != currentUser.ID && !currentUser.HasPermission(PermissionAdmin) {
return c.Status(403).SendString("Forbidden")
}
user, err := db.GetUserByID(id)
if err != nil {
return c.Status(404).SendString("Not Found")
}
return c.JSON(user.ToResponse(currentUser))
})
middleBrick's continuous monitoring in the Pro plan would automatically scan your Fiber APIs on a configurable schedule, detecting any new Broken Access Control vulnerabilities that emerge during development. The GitHub Action integration allows you to fail builds if security scores drop below your threshold, preventing vulnerable code from reaching production.
For comprehensive protection, combine these code-level fixes with middleBrick's scanning to verify that all authorization logic is correctly implemented and that no new vulnerabilities have been introduced.