Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 922

Show
Ignore:
Timestamp:
01/10/06 15:47:24
Author:
fumanchu
Message:

A more inclusive, os-level check for staticfilter uplevel attacks.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/filters/staticfilter.py

    r921 r922  
    2424                return 
    2525         
     26        root = config.get('static_filter.root', '').rstrip(r"\/") 
    2627        filename = config.get('static_filter.file') 
    27         if not filename: 
     28        if filename: 
     29            staticDir = None 
     30        else: 
    2831            staticDir = config.get('static_filter.dir') 
    2932            if not staticDir: 
     
    3942            extraPath = urllib.unquote(extraPath) 
    4043            # If extraPath is "", filename will end in a slash 
    41             if '..' in extraPath: 
    42                 # Disallow '..' (security flaw) 
    43                 raise cherrypy.HTTPError(403) # Forbidden 
    4444            filename = os.path.join(staticDir, extraPath) 
    4545         
     
    4848        # a relative path to serveFile. 
    4949        if not os.path.isabs(filename): 
    50             root = config.get('static_filter.root', '').rstrip(r"\/") 
    5150            if not root: 
    5251                msg = ("StaticFilter requires an absolute final path. " 
     
    5554            filename = os.path.join(root, filename) 
    5655         
     56        # If we used static_filter.dir, then there's a chance that the 
     57        # extraPath pulled from the URL might have ".." or similar uplevel 
     58        # attacks in it. Check that the final file is a child of staticDir. 
     59        # Note that we do not check static_filter.file--that can point 
     60        # anywhere (since it does not use the request URL). 
     61        if staticDir: 
     62            if not os.path.isabs(staticDir): 
     63                staticDir = os.path.join(root, staticDir) 
     64            if not os.path.normpath(filename).startswith(os.path.normpath(staticDir)): 
     65                raise cherrypy.HTTPError(403) # Forbidden 
     66             
    5767        try: 
    5868            cptools.serveFile(filename) 

Hosted by WebFaction

Log in as guest/cpguest to create tickets