Request data stored in class variables

User-specific request data is stored in class variables.

Description

User names or session values stored on a class can be read by other requests in the same process. They persist even when requests run sequentially.

Potential impact

Another user’s identity may be disclosed or used in an authorization decision.

Remediation

Use local variables or a new instance for each request. Store values that must persist in the user’s own session. Keep user-specific data out of class variables and module globals.

Examples

Before

python
class UserDescription:
    user_name = ""

def update_description(request):
    UserDescription.user_name = request.POST.get("name")

After

python
class UserDescription:
    def __init__(self, user_name):
        self.user_name = user_name

def update_description(request):
    return UserDescription(request.POST.get("name"))

The first function changes UserDescription.user_name. The second returns a new object with its own self.user_name. Reusing that object across users would share the value again.

References