mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-05 18:11:41 +00:00
Structure changes to match other projects and minor logging improvements
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
import logging
|
||||
|
||||
from tornado.web import StaticFileHandler, HTTPError
|
||||
|
||||
|
||||
class QuietStaticFileHandler(StaticFileHandler):
|
||||
"""Minor override of logging in StaticFileHandler to log HTTP errors at debug level instead of their usual
|
||||
warning level. Without this, attacks on Spothole which try to do path traversal attacks would log exceptions
|
||||
from inside Tornado, and the server logs would contain a lot of this type of content. This effectively changes
|
||||
the log level of these exceptions to DEBUG so they are only logged if DEBUG level logging is enabled."""
|
||||
|
||||
def log_exception(self, typ, value, tb):
|
||||
if isinstance(value, HTTPError):
|
||||
logging.debug(value)
|
||||
return
|
||||
super().log_exception(typ, value, tb)
|
||||
+6
-3
@@ -18,7 +18,6 @@ from server.handlers.api.status import APIStatusHandler
|
||||
from server.handlers.manifesthandler import ManifestHandler
|
||||
from server.handlers.metrics import PrometheusMetricsHandler
|
||||
from server.handlers.pagetemplate import PageTemplateHandler
|
||||
from server.handlers.quietstaticfilehandler import QuietStaticFileHandler
|
||||
|
||||
_HERE = os.path.dirname(__file__ or "")
|
||||
|
||||
@@ -101,12 +100,16 @@ class WebServer:
|
||||
if ALLOW_SPOTTING:
|
||||
ui_routes += [(r"/add-spot", PageTemplateHandler, {"template_name": "add_spot", **handler_opts})]
|
||||
|
||||
# API docs, Prometheus metrics, webapp manifest and static assets are always available regardless of API-only mode.
|
||||
# API docs, Prometheus metrics, webapp manifest and static assets are always available regardless of API-only
|
||||
# mode.
|
||||
misc_routes = [
|
||||
(r"/apidocs", PageTemplateHandler, {"template_name": "apidocs", **handler_opts}),
|
||||
(r"/metrics", PrometheusMetricsHandler),
|
||||
(r"/manifest.webmanifest", ManifestHandler),
|
||||
(r"/static/(.*)", QuietStaticFileHandler, {"path": os.path.join(_HERE, "../webassets")})
|
||||
# If e.g. nginx is configured as a reverse proxy with a hard-coded path to static files, as per the README,
|
||||
# this will never have to handle anything, but having it here allows Spothole to work without nginx for
|
||||
# testing.
|
||||
(r"/static/(.*)", StaticFileHandler, {"path": os.path.join(_HERE, "../static")})
|
||||
]
|
||||
|
||||
app = tornado.web.Application(api_routes + ui_routes + misc_routes,
|
||||
|
||||
Reference in New Issue
Block a user