HIGH pii leakagefiber

Pii Leakage in Fiber

Fiber-Specific Remediation

Remediating PII leakage in Fiber applications requires a multi-layered approach combining input validation, output filtering, and secure error handling. The first layer is implementing proper data sanitization before database queries:

app.Get("/api/users/:id", func(c *fiber.Ctx) error {
    id := c.Params("id")
    
    // Validate ID format before query
    if !isValidUUID(id) {
        return c.Status(400).JSON(fiber.Map{
            "error": "Invalid user ID format",
        })
    }
    
    var user User
    result := db.First(&user, id)
    
    // Generic error message without revealing existence
    if result.RowsAffected == 0 {
        return c.Status(404).JSON(fiber.Map{
            "error": "Resource not found",
        })
    }
    
    // Filter sensitive fields before response
    response := map[string]interface{}{
        "id": user.ID,
        "name": user.Name,
        "created_at": user.CreatedAt,
    }
    
    return c.JSON(response)
})

This approach validates input format, uses generic error messages, and explicitly filters the response to exclude sensitive fields like email, phone, and address.

For logging middleware, implement proper redaction:

app.Use(func(c *fiber.Ctx) error {
    // Create redacted copy of headers
    redactedHeaders := c.Fasthttp().Request.Header.Clone()
    
    // Remove sensitive headers
    redactedHeaders.Del("Authorization")
    redactedHeaders.Del("Cookie")
    redactedHeaders.Del("Set-Cookie")
    
    log.Printf("Request: %s %s from %s",
        c.Method(), c.Path(), c.IP())
    
    return c.Next()
})

Implement secure error handling middleware to prevent stack trace exposure:

app.Use(func(c *fiber.Ctx) error {
    return c.Next()
}, func(err error, c *fiber.Ctx) error {
    // Log the actual error internally
    log.Printf("Error: %v", err)
    
    // Return generic error to client
    return c.Status(500).JSON(fiber.Map{
        "error": "Internal server error",
    })
})

For query parameter handling, implement input validation and sanitization:

app.Get("/search", func(c *fiber.Ctx) error {
    query := c.Query("q")
    
    // Validate and sanitize input
    if len(query) > 255 {
        return c.Status(400).JSON(fiber.Map{
            "error": "Query too long",
        })
    }
    
    // Sanitize to prevent injection
    sanitizedQuery := sanitizeInput(query)
    
    results := searchDatabase(sanitizedQuery)
    
    return c.JSON(fiber.Map{
        "results": results,
        // Never echo back raw query
    })
})

Additionally, implement response filtering for all API endpoints using middleware:

func filterSensitiveData(next fiber.Handler) fiber.Handler {
    return func(c *fiber.Ctx) error {
        // Execute the handler
        err := next(c)
        
        // If response is JSON, filter sensitive fields
        if c.Response().Header.ContentType() == "application/json" {
            var data map[string]interface{}
            if err := json.Unmarshal(c.Response().Body(), &data); err == nil {
                // Remove sensitive keys
                for _, key := range []string{"email", "phone", "ssn", "password"} {
                    delete(data, key)
                }
                
                // Re-serialize filtered response
                filtered, _ := json.Marshal(data)
                c.Response().SetBody(filtered)
            }
        }
        
        return err
    }
}

app.Use(filterSensitiveData)

This comprehensive approach ensures PII is protected at every layer of your Fiber application, from input validation through response filtering and secure error handling.

Related CWEs: dataExposure

CWE IDNameSeverity
CWE-200Exposure of Sensitive Information HIGH
CWE-209Error Information Disclosure MEDIUM
CWE-213Exposure of Sensitive Information Due to Incompatible Policies HIGH
CWE-215Insertion of Sensitive Information Into Debugging Code MEDIUM
CWE-312Cleartext Storage of Sensitive Information HIGH
CWE-359Exposure of Private Personal Information (PII) HIGH
CWE-522Insufficiently Protected Credentials CRITICAL
CWE-532Insertion of Sensitive Information into Log File MEDIUM
CWE-538Insertion of Sensitive Information into Externally-Accessible File HIGH
CWE-540Inclusion of Sensitive Information in Source Code HIGH

Frequently Asked Questions

How does middleBrick's PII detection differ from standard security scanners?
middleBrick specifically targets Fiber's response patterns and common Go web application vulnerabilities. Unlike generic scanners that look for basic injection patterns, middleBrick understands Fiber's JSON handling, error response formats, and middleware architecture. It tests for PII leakage through Fiber-specific channels like Fasthttp header handling, error middleware exposure, and the framework's direct struct-to-JSON serialization patterns that often inadvertently expose sensitive fields.
Can middleBrick detect PII leakage in authenticated endpoints?
middleBrick's standard scanning tests unauthenticated endpoints, but the Pro plan includes authenticated scanning capabilities. For PII detection specifically, middleBrick can test authenticated routes when provided with valid credentials or tokens. This is crucial for detecting PII leakage in user-specific endpoints where sensitive data might only be exposed to authenticated users. The scanner validates whether authentication properly restricts access to sensitive user information.