From e6ddf2f12078da199adaf055e0b20538c9ebc0ed Mon Sep 17 00:00:00 2001 From: codl Date: Thu, 31 Aug 2017 20:46:38 +0200 Subject: [PATCH] add sentry js back in --- app.py | 3 ++- routes.py | 15 +++++++++++---- templates/lib/layout.html | 6 +++--- templates/sentry.js | 1 + 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 templates/sentry.js diff --git a/app.py b/app.py index 476d7ae..082ab4c 100644 --- a/app.py +++ b/app.py @@ -81,13 +81,14 @@ def install_security_headers(resp): csp = ("default-src 'none';" "img-src 'self' https:;" "style-src 'self' 'unsafe-inline';" - "connect-src 'self';" "frame-ancestors 'none';" ) if 'SENTRY_DSN' in app.config: csp += "script-src 'self' https://cdn.ravenjs.com/;" + csp += "connect-src 'self' https://sentry.io/;" else: csp += "script-src 'self';" + csp += "connect-src 'self';" if 'CSP_REPORT_URI' in app.config: csp += "report-uri " + app.config.get('CSP_REPORT_URI') diff --git a/routes.py b/routes.py index 70018ce..b5867aa 100644 --- a/routes.py +++ b/routes.py @@ -40,10 +40,7 @@ def inject_version(): @app.context_processor def inject_sentry(): if sentry: - client_dsn = app.config.get('SENTRY_DSN').split('@') - client_dsn[:1] = client_dsn[0].split(':') - client_dsn = ':'.join(client_dsn[0:2]) + '@' + client_dsn[3] - return dict(sentry_dsn=client_dsn) + return dict(sentry=True) return dict() @@ -338,3 +335,13 @@ def mastodon_login_step2(instance_url): g.viewer = sess return redirect(url_for('index')) + +@app.route('/sentry/setup.js') +def sentry_setup(): + client_dsn = app.config.get('SENTRY_DSN').split('@') + client_dsn[:1] = client_dsn[0].split(':') + client_dsn = ':'.join(client_dsn[0:2]) + '@' + client_dsn[3] + resp = make_response(render_template( + 'sentry.js', sentry_dsn = client_dsn)) + resp.headers.set('content-type', 'text/javascript') + return resp diff --git a/templates/lib/layout.html b/templates/lib/layout.html index 5fd3a7a..c33a732 100644 --- a/templates/lib/layout.html +++ b/templates/lib/layout.html @@ -13,9 +13,9 @@ - {% if sentry_dsn -%} - + {% if sentry -%} + + {% endif -%} {% block scripts %}{% endblock %} diff --git a/templates/sentry.js b/templates/sentry.js new file mode 100644 index 0000000..7b88e95 --- /dev/null +++ b/templates/sentry.js @@ -0,0 +1 @@ +Raven.config('{{sentry_dsn}}').install()