﻿# V5922\. OWASP\. Possible trust boundary violation\. Potentially tainted data is stored in a trusted storage\.

The analyzer has detected data written to the session or request context from an unvalidated external source\. If an application treats such data as trusted, this could lead to a breach of the trust boundary\.

This vulnerability can be categorized under the OWASP Top 10 Application Security Risks 2025 classification as follows: [A06:2025 Insecure Design](https://top10.owasp.org/2025/A06_2025-Insecure_Design/)\.

The trust boundary distinguishes between user\-supplied data, which may be anything, and data that the application has already verified\. Both the session and the request context are on the trusted side of the boundary, and code that accesses them usually does not revalidate their values\. If user data is entered without verification, the user can assign themselves a role, user ID, or access rights\.

The example:

```cpp
func login(w http.ResponseWriter, r *http.Request) {
  username := r.FormValue("username")
  role := r.FormValue("role")

  session, _ := store.Get(r, "app-session")
  session.Values["user"] = username
  session.Values["role"] = role
  session.Save(r, w)
}

func adminPanel(w http.ResponseWriter, r *http.Request) {
  session, _ := store.Get(r, "app-session")
  if session.Values["role"] != "admin" {
    http.Error(w, "forbidden", http.StatusForbidden)
    return
  }
  ....
}
```

The user's role is retrieved from a form parameter and stored in the session\. The `adminPanel` handler trusts the value from the session, so any client that sends `role=admin` is granted access to the admin panel\.

The values on which permissions depend must be determined on the server\. For example, they should be retrieved from a database using a verified user ID or from a token with a verified signature:

```cpp
func login(w http.ResponseWriter, r *http.Request) {
  username := r.FormValue("username")

  var role string
  var hash []byte
  err := db.QueryRow("SELECT role, password FROM users WHERE username = ?",
                     username).Scan(&role, &hash)
  if err != nil {
    http.Error(w, "unauthorized", http.StatusUnauthorized)
    return
  }

  if bcrypt.CompareHashAndPassword(hash, 
      []byte(r.FormValue("password"))) != nil {
    http.Error(w, "unauthorized", http.StatusUnauthorized)
    return
  }

  session, _ := store.Get(r, "app-session")
  session.Values["user"] = username
  session.Values["role"] = role
  session.Save(r, w)
}
```

The role is retrieved from the database, and the username is added to the session only after the password has been successfully verified against the hash associated with that username\.