Skip to content

[Security/DoS] AST Parser Bomb (Denial of Service) via deeply nested Python code in ast_analyzer.py #1004

@sonusharma6-dsa

Description

@sonusharma6-dsa

Summary

The analyze function in backend/app/services/ast_analyzer.py utilizes the standard library ast.parse() to analyze incoming Python code snippets. However, ast.parse() is vulnerable to C-level stack exhaustion when provided with extremely deeply nested expressions (e.g., ((((...))))). This crashes the underlying CPython process, causing a complete Denial of Service for the application server.

Impact

An attacker can submit a relatively small payload containing 5000+ nested brackets, crashing the FastAPI server worker instantly without memory or CPU warning.

Proposed Fix

Implement a pre-flight depth check to abort parsing if consecutive opening brackets exceed a safe limit (e.g., 150) before executing ast.parse().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions