{"record":{"id":"94254ed79540cdbe","repo":"Significant-Gravitas/AutoGPT","slug":"reviewed-data-has-excessive-nesting-depth","errorCode":null,"errorMessage":"reviewed_data has excessive nesting depth","messagePattern":"reviewed_data has excessive nesting depth","errorType":"validation","errorClass":"ValueError","httpStatus":422,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/executions/review/model.py","lineNumber":181,"sourceCode":"            else:\n                return False\n\n        if not validate_safejson_type(v):\n            raise ValueError(\"reviewed_data contains non-SafeJson compatible types\")\n\n        # Validate data size to prevent DoS attacks\n        try:\n            json_str = json.dumps(v)\n            if len(json_str) > 1000000:  # 1MB limit\n                raise ValueError(\"reviewed_data is too large (max 1MB)\")\n        except (TypeError, ValueError) as e:\n            raise ValueError(f\"reviewed_data must be JSON serializable: {str(e)}\")\n\n        # Ensure no dangerous nested structures (prevent infinite recursion)\n        def check_depth(obj, max_depth=10, current_depth=0):\n            \"\"\"Recursively check object nesting depth to prevent stack overflow attacks.\"\"\"\n            if current_depth > max_depth:\n                raise ValueError(\"reviewed_data has excessive nesting depth\")\n\n            if isinstance(obj, dict):\n                for value in obj.values():\n                    check_depth(value, max_depth, current_depth + 1)\n            elif isinstance(obj, list):\n                for item in obj:\n                    check_depth(item, max_depth, current_depth + 1)\n\n        check_depth(v)\n        return v\n\n    @field_validator(\"message\")\n    @classmethod\n    def validate_message(cls, v):\n        \"\"\"Validate and sanitize review message.\"\"\"\n        if v is not None and len(v.strip()) == 0:\n            return None\n        return v","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/executions/review/model.py#L163-L199","documentation":"ValueError raised by check_depth when reviewed_data nests deeper than 10 levels (dicts/lists counted). It prevents stack-overflow style recursion attacks against the executor that replays this data. Pydantic surfaces it as 422.","triggerScenarios":"Submitting deeply nested structures — e.g. a recursively built tree, a self-referential graph serialized naively, or adversarial 20-level nested arrays. Depth is counted on both dict and list descent, so wide-but-shallow data is fine.","commonSituations":"Serializing org charts, ASTs, or threaded comment trees without flattening; generators that accidentally recurse (children containing themselves).","solutions":["Flatten deep trees before submission (e.g. children-as-ids instead of nested objects)","Add a client-side depth check mirroring max_depth=10","Break cycles with reference ids"],"exampleFix":"# before\nreviewed_data=deep_tree  # 15 levels\n# after\nreviewed_data=flatten_tree(deep_tree, max_depth=10)","handlingStrategy":"validation","validationCode":"function depth(obj: unknown, d = 0): number {\n  if (obj && typeof obj === 'object')\n    return Math.max(...Object.values(obj as object).map(v => depth(v, d + 1)));\n  return d;\n}\nif (depth(reviewedData) > 10) throw new Error('too deep');","typeGuard":"const withinDepth = (o: unknown, max = 10, d = 0): boolean =>\n  d > max ? false : o && typeof o === 'object'\n    ? Object.values(o).every(v => withinDepth(v, max, d + 1)) : true;","tryCatchPattern":null,"preventionTips":["Flatten trees to id references before submission","Break cycles with reference ids","Mirror the max_depth=10 constant client-side"],"tags":["pydantic","validation","nesting-limit","dos-guard"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}