Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Research multiple csp violation error caught on production api logs #3198

Closed
1 task
Tracked by #137
pkfec opened this issue Sep 24, 2019 · 6 comments
Closed
1 task
Tracked by #137

Research multiple csp violation error caught on production api logs #3198

pkfec opened this issue Sep 24, 2019 · 6 comments
Assignees
Labels

Comments

@pkfec
Copy link
Contributor

pkfec commented Sep 24, 2019

Summary

Content security policy is blocking google analytics and DAP analytics from the front end portion of the API: https://api.open.fec.gov/developers/

Examples of violations
2019-09-24T15:55:26.04-0400 [APP/PROC/WEB/5] ERR {'csp-report': {'document-uri': 'https://www.fec.gov/data/candidates/?election_year=2020&party=DEM&state=TX&district=31', 'referrer': '', 'violated-directive': 'img-src', 'effective-directive': 'img-src', 'original-policy': "default-src 'self' .fec.gov .app.cloud.gov https://www.google-analytics.com; frame-src 'self' https://www.google.com/recaptcha/ https://www.youtube.com/; img-src 'self' data: https://.ssl.fastly.net https://www.google-analytics.com .app.cloud.gov; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/ https://www.google-analytics.com https://polyfill.io https://dap.digitalgov.gov; style-src 'self' data: 'unsafe-inline'; object-src 'none'; report-uri https://api.open.fec.gov/report-csp-violation/?api_key=oXy*************;", 'disposition': 'enforce', 'blocked-uri': 'https://datapro.website/metric/?mid=&wid=52526&sid=&tid=8385&rid=URL_IGNOREDOMAIN&t=1569354925660', 'status-code': 0, 'script-sample': ''}}```

2019-09-24T15:59:45.43-0400 [APP/PROC/WEB/1] ERR {‘csp-report’: {‘document-uri’: ’https://www.fec.gov/data/elections/house/CA/25/2020/', ‘referrer’: ‘https://www.fec.gov/data/elections/?cycle=2020&zip=91350’, ‘violated-directive’: ‘font-src’, ‘effective-directive’: ‘font-src’, ‘original-policy’: “default-src ‘self’ *.fec.gov .app.cloud.gov https://www.google-analytics.com; frame-src ‘self’ https://www.google.com/recaptcha/ https://www.youtube.com/; img-src ‘self’ data: https://.ssl.fastly.net https://www.google-analytics.com *.app.cloud.gov; script-src ‘self’ ‘unsafe-inline’ ‘unsafe-eval’ https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/ https://www.google-analytics.com https://polyfill.io https://dap.digitalgov.gov; style-src ‘self’ data: ‘unsafe-inline’; object-src ‘none’; report-uri https://api.open.fec.gov/report-csp-violation/?api_key=oXy***************;“, ‘disposition’: ‘enforce’, ‘blocked-uri’: ‘data’, ‘status-code’: 0, ‘script-sample’: ‘’}}

2019-09-24T16:06:28.01-0400 [APP/PROC/WEB/0] ERR {'csp-report': {'document-uri': 'https://www.fec.gov/data/', 'referrer': '', 'violated-directive': 'font-src', 'effective-directive': 'font-src', 'original-policy': "default-src 'self' .fec.gov .app.cloud.gov https://www.google-analytics.com; frame-src 'self' https://www.google.com/recaptcha/ https://www.youtube.com/; img-src 'self' data: https://.ssl.fastly.net https://www.google-analytics.com .app.cloud.gov; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/ https://www.google-analytics.com https://polyfill.io https://dap.digitalgov.gov; style-src 'self' data: 'unsafe-inline'; object-src 'none'; report-uri https://api.open.fec.gov/report-csp-violation/?api_key=oXy************;", 'disposition': 'enforce', 'blocked-uri': 'data', 'status-code': 0, 'script-sample': ''}}

** Screen shot from browser console **

Screen Shot 2019-10-03 at 11 14 08 AM

Completion Criteria

  • Understand the issue and propose solution
@pkfec pkfec added the Bug label Sep 24, 2019
@lbeaufort lbeaufort added this to the Sprint 10.3 milestone Oct 2, 2019
@lbeaufort lbeaufort changed the title Multiple csp violation error caught on production api logs Research multiple csp violation error caught on production api logs Oct 2, 2019
@pkfec
Copy link
Contributor Author

pkfec commented Oct 12, 2019

CSP Highlights:

  1. Content restrictions on a website to control the resources that are loaded when a end user visits the website.
  2. Content restrictions are enforced by browsers
  3. Different browsers generate reports

@PaulClark2 PaulClark2 modified the milestones: Sprint 10.3, Sprint 10.4 Oct 22, 2019
@pkfec
Copy link
Contributor Author

pkfec commented Oct 22, 2019

With the help of @jason-upchurch python program that extracts and displays the directives in a table format i have uploaded the results here:
https://docs.google.com/spreadsheets/d/1M5Wzb8QtMDFEe7wBqx5F0IAz7DCdJazJ/edit?dls=true#gid=650634757

csp violated-directives found so far in prod space:

  1. font-src
  2. default-src
  3. img-src
  4. script-src-elem
  5. script-src

thanks @jason-upchurch for all the help. We can reuse python script below to export only the csp report directives into a table.
Here is the script:
csp_report.txt

@pkfec
Copy link
Contributor Author

pkfec commented Oct 23, 2019

@patphongs could you please take a look at the violated directives and make necessary code changes on cms or api? Later we can deploy and test if any new directive are being flagged in the logs. I can create a follow up ticket if we decide to make any code changes.

@patphongs
Copy link
Member

patphongs commented Oct 25, 2019

Thanks @pkfec for the report. It's hard for me to tell where these violations are happening with this data. Even though it provides the URL, when I go to the page of the violation, I don't see any CSP errors reported in the console. I'll need some more time to analyze it I think.

@pkfec
Copy link
Contributor Author

pkfec commented Oct 28, 2019

@patphongs Like i mentioned, these reports are OS and browser specific. I had hard time reproducing the reports on my local.

csp-reports will be disabled in production after the 10.4 release which is schedule on 11/12 : PR ##3297.

@jason-upchurch
Copy link
Contributor

research complete and closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants