GuardAPI Logo
GuardAPI

Fix Shadow API Exposure in CherryPy

Shadow APIs in CherryPy typically arise from the framework's 'exposed' attribute pattern and its hierarchical tree-based dispatching. When developers inadvertently mark internal methods as exposed or fail to restrict HTTP verbs, they create undocumented attack surfaces. This guide focuses on neutralizing these hidden endpoints by enforcing strict dispatching and explicit method whitelisting.

The Vulnerable Pattern

import cherrypy

class ShadowAPI(object): @cherrypy.expose def index(self): return “Public API v1”

@cherrypy.expose
def internal_debug_status(self):
    # SHADOW ENDPOINT: Exposed but undocumented
    return {"db_creds": "admin:password123", "status": "leaking"}

if name == ‘main’: cherrypy.quickstart(ShadowAPI())

The Secure Implementation

To kill Shadow APIs in CherryPy, you must transition from 'Discovery-based' routing to 'Explicit' routing. 1. Remove the @cherrypy.expose decorator from any method not intended for public consumption. 2. Implement 'cherrypy.tools.allow' to strictly enforce HTTP verbs (GET, POST, etc.), preventing attackers from probing endpoints with unexpected methods. 3. Use 'cherrypy.dispatch.MethodDispatcher()' in your configuration; this forces the engine to map requests directly to HTTP-named methods (def GET, def POST) rather than any attribute with an 'exposed' flag, effectively neutralizing accidental exposure of helper functions.

import cherrypy

class ValidatedAPI(object): # Explicitly define allowed methods _cp_config = { ‘tools.allow.on’: True, ‘tools.allow.methods’: [‘GET’] }

@cherrypy.expose
@cherrypy.tools.json_out()
def index(self):
    return {"status": "secure"}

def internal_logic(self):
    # NO @cherrypy.expose - This cannot be reached via URL
    return "Private"

Using MethodDispatcher to prevent unintended tree traversal

if name == ‘main’: conf = { ’/’: { ‘request.dispatch’: cherrypy.dispatch.MethodDispatcher(), ‘tools.sessions.on’: True, } } # Note: MethodDispatcher expects classes with GET/POST/PUT methods cherrypy.quickstart(ValidatedAPI(), ’/’, conf)

System Alert • ID: 9343
Target: CherryPy API
Potential Vulnerability

Your CherryPy API might be exposed to Shadow API Exposure

74% of CherryPy apps fail this check. Hackers use automated scanners to find this specific flaw. Check your codebase before they do.

RUN FREE SECURITY DIAGNOSTIC
GuardLabs Engine: ONLINE

Free Tier • No Credit Card • Instant Report

Verified by Ghost Labs Security Team

This content is continuously validated by our automated security engine and reviewed by our research team. Ghost Labs analyzes over 500+ vulnerability patterns across 40+ frameworks to provide up-to-date remediation strategies.