Pii Leakage in Echo Go
How PII Leakage Manifests in Echo Go
PII leakage in Echo Go applications typically occurs through several Echo Go-specific code patterns. The most common manifestation is through Echo Go's context-based request handling, where sensitive user data gets inadvertently included in API responses or logged to stdout/stderr.
A frequent vulnerability appears in Echo Go's middleware chain. When developers use Echo Go's c.Context() to pass user data between handlers, they often forget to sanitize this data before sending responses. For example:
func getUserProfile(c echo.Context) error {
user := c.Get("user").(*User)
return c.JSON(http.StatusOK, user) // PII exposed: email, phone, address
}Another Echo Go-specific pattern involves the framework's automatic JSON binding. Echo Go's c.Bind() method unmarshals request bodies directly into structs without validation, potentially exposing unmapped fields:
type User struct {
ID int `json:"id"`
Email string `json:"email"`
Password string `json:"password"` // Exposed if not tagged properly
}
func createUser(c echo.Context) error {
user := new(User)
if err := c.Bind(user); err != nil {
return err
}
return c.JSON(http.StatusCreated, user) // Password leaked!
}Echo Go's logging system presents another attack vector. The framework's default logger captures full request bodies and response data, which may contain PII:
e := echo.New()
e.Logger.Info("Request processed: " + c.Request().Body) // Full body logged
Echo Go's parameter binding also contributes to PII exposure. Path parameters and query strings are automatically bound to struct fields, and developers may inadvertently return these directly:
func getSensitiveData(c echo.Context) error {
id := c.Param("userId") // User ID from URL
data := fetchSensitiveData(id)
return c.JSON(http.StatusOK, data) // PII in response without authorization check
}Echo Go-Specific Detection
Detecting PII leakage in Echo Go applications requires understanding the framework's unique patterns. The most effective approach combines static analysis with runtime scanning using middleBrick's API security scanner.
middleBrick's Echo Go-specific detection identifies PII leakage through several mechanisms. The scanner examines your Echo Go application's OpenAPI specification and runtime behavior to detect exposed endpoints that handle sensitive data. It specifically looks for Echo Go's context-based data passing patterns and middleware implementations.
To scan an Echo Go API with middleBrick:
middlebrick scan https://api.yourechoapp.com --api-spec openapi.json
middleBrick tests Echo Go applications by sending requests to endpoints and analyzing responses for PII patterns. It checks for common Echo Go vulnerabilities like:
- Echo Go context data exposure in JSON responses
- Unvalidated request body binding
- Echo Go logger PII capture
- Echo Go parameter binding without authorization
- Echo Go middleware chain data leakage
The scanner also validates Echo Go's OpenAPI specifications against runtime behavior, ensuring that documented endpoints match actual implementations and that sensitive data fields are properly secured.
For Echo Go applications using Echo Go's built-in validation, middleBrick checks whether validation rules adequately protect PII. It tests whether Echo Go's Validate() method is properly configured to reject malicious input that could lead to PII exposure.
Echo Go-Specific Remediation
Remediating PII leakage in Echo Go requires leveraging the framework's built-in features while following security best practices. Echo Go provides several mechanisms to prevent PII exposure.
First, use Echo Go's context binding with explicit data sanitization:
func getUserProfile(c echo.Context) error {
user := c.Get("user").(*User)
// Sanitize response - remove sensitive fields
safeUser := struct {
ID int `json:"id"`
Name string `json:"name"`
Email string `json:"email"` // Only if appropriate for this endpoint
}{
ID: user.ID,
Name: user.Name,
Email: user.Email,
}
return c.JSON(http.StatusOK, safeUser)
}Echo Go's JSON binding can be secured using struct tags and validation:
type User struct {
ID int `json:"id"`
Email string `json:"email"`
Password string `json:"-"` // Exclude from JSON output
SSN string `json:"-"`
}
func createUser(c echo.Context) error {
user := new(User)
if err := c.Bind(user); err != nil {
return c.JSON(http.StatusBadRequest, echo.Map{"error": err.Error()})
}
// Validate before processing
if err := validate.Struct(user); err != nil {
return c.JSON(http.StatusBadRequest, echo.Map{"error": "Invalid input"})
}
return c.JSON(http.StatusCreated, echo.Map{"message": "User created"})
}Echo Go's middleware system can be used to implement PII filtering:
func piiFilter(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
err := next(c)
// Check response for sensitive data
if response, ok := c.Get("response").(map[string]interface{}); ok {
// Remove PII fields
delete(response, "ssn")
delete(response, "credit_card")
}
return err
}
}
e := echo.New()
e.Use(piiFilter)
Echo Go's logging can be configured to exclude PII:
e.Logger.SetLevel(log.ERROR)
e.Use(middleware.BodyLimit("10M"))
e.Use(middleware.CORS())
// Custom logger that filters PII
customLogger := middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "${time_rfc3339} ${status} ${method} ${uri} ${latency_human} ${bytes_in} ${bytes_out}\n",
})
e.Use(customLogger)
Related CWEs: dataExposure
| CWE ID | Name | Severity |
|---|---|---|
| CWE-200 | Exposure of Sensitive Information | HIGH |
| CWE-209 | Error Information Disclosure | MEDIUM |
| CWE-213 | Exposure of Sensitive Information Due to Incompatible Policies | HIGH |
| CWE-215 | Insertion of Sensitive Information Into Debugging Code | MEDIUM |
| CWE-312 | Cleartext Storage of Sensitive Information | HIGH |
| CWE-359 | Exposure of Private Personal Information (PII) | HIGH |
| CWE-522 | Insufficiently Protected Credentials | CRITICAL |
| CWE-532 | Insertion of Sensitive Information into Log File | MEDIUM |
| CWE-538 | Insertion of Sensitive Information into Externally-Accessible File | HIGH |
| CWE-540 | Inclusion of Sensitive Information in Source Code | HIGH |