Skip to content

Commit

Permalink
Issue #1329. Add a /csp-report endpoint for simple logging of violati…
Browse files Browse the repository at this point in the history
…ons.
  • Loading branch information
Mike Taylor committed Feb 28, 2017
1 parent c2c8467 commit cece38a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

LOG_FILE = '/tmp/webcompat.log'
LOG_FMT = '%(asctime)s tracking %(message)s'
CSP_REPORTS_LOG = '/tmp/webcompat-csp-reports.log'

# Status categories used in the project
# 'new', 'needsdiagnosis', 'needscontact', 'contactready' , 'sitewait', 'close'
Expand Down
10 changes: 10 additions & 0 deletions webcompat/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,13 @@ def contributors():
def cssfixme():
'''Route for CSS Fix me tool'''
return render_template('cssfixme.html')


@app.route('/csp-report', methods=['POST'])
def log_report():
'''Route to record CSP header violations.'''
if 'application/csp-report' not in request.headers.get('content-type'):
return ('Wrong Content-Type.', 400)
with open(app.config['CSP_REPORTS_LOG'], 'a') as r:
r.write(request.data + '\n')
return ('', 204)

0 comments on commit cece38a

Please sign in to comment.