-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Security][High] csrftoken set via HTTP, not HTTPS (due 3/8/25) #1321
Comments
Dan Fowlkes commented: BLUF: I believe that this is almost entirely mitigated by our web-app config which exclusively uses HTTPS, therefore web-app will never call web-api via HTTP. The only way someone could MITM an HTTP request to web-api would be if they were calling the APIs directly over HTTP (as the vuln test did) and then it may only work for the first request. In my testing I believe that was able to reproduce this initially. After some additional testing I went back to take screenshots of the evidence to include in this write-up but was unable to reproduce that initial success. One possibility is that this issue only manifests the first time after which the HTTP301 Permanent Redirect from HTTP to HTTPS prevents the possibility of it happening again (even after clearing the host cache and disabling caching, restarting the browser, etc.) Subsequent attempts to hit via HTTP resulted in HTTP307 Internal Redirects at best, with no cookie set until already on HTTPS. The other possibility is that I never reproduced the issue at all and that I didn’t notice, when examining request headers and response headers when I’d switched from HTTP to HTTPS. Regardless. According to the scan findings report excerpted above, this issue occurs if/when one intentionally goes to http://test-api.fecfile.fec.gov/, which rightly responds with an HTTP301 permanent redirect to https://test-api.fecfile.fec.gov/ BUT allegedly (the very first time?) also responds with a csrftoken while still on HTTP. Should this happen it would be a Severity level 1 finding (-- the lowest) per the report. In all subsequent testing, I have found that (based on the headers) the redirect from HTTP to HTTPS is happening in CloudFront before ever reaching the server, which does not forward cookies through by default. Have we created a whitelist in CF with csrftoken? Regardless, the only way that this could be reproduced would be intentionally hitting our APIs via HTTP. This could happen at most once due to CF responding with an HTTP301 Permanent Redirect from HTTP and HTTPS. So long as web-app calls web-api via HTTPS there is no danger. |
Dan Fowlkes commented: In further testing, AWS Cloudfront redirects HTTP requests to HTTPS with a 301 Permanent Redirect before they reach nginx, much less django: {noformat}$ curl -v http://test-api.fecfile.fec.gov
< HTTP/1.1 301 Moved Permanently No csrf token cookie is set hitting (just) [test-api.fecfile.fec.gov|http://test-api.fecfile.fec.gov] via HTTPS: {noformat}$ curl -v -c - https://test-api.fecfile.fec.gov
Netscape HTTP Cookie Filehttps://curl.se/docs/http-cookies.htmlThis file was generated by libcurl! Edit at your own risk.{noformat}Whereas it is set hitting [test-api.fecfile.fec.gov/api/docs/|http://test-api.fecfile.fec.gov/api/docs/]: {noformat}$ curl -v -c - https://test-api.fecfile.fec.gov/api/docs/
Netscape HTTP Cookie Filehttps://curl.se/docs/http-cookies.htmlThis file was generated by libcurl! Edit at your own risk..fecfile.fec.gov TRUE / TRUE 1770941807 csrftoken 0yKj9gTs4eW2am6I4c5ToSESMZsuwbpn{noformat} |
Dan Fowlkes commented: Conclusion? I am leaning toward the belief that this is a false positive and that the tool is mistaken that it is still operating over HTTP when the csrf token cookie is set. |
Description:
Cookie with a "secure" attribute was initially set by an insecure connection; i.e. HTTP vs HTTPS. (INFO, Severity level 1)
During the initial setting of the secure cookie through an insecure connection, a Man In The Middle attack could be performed and cookie data can be stolen; the cookie will then be transmitted to the server only using a secure connection. In this case, the "secure" attribute will not protect the cookie as it could be compromised in the setting phase.
| Request Method | Request URL | Request Headers | Response | | GET | http://test-api.fecfile.fec.gov/ | Host: test-api.fecfile.fec.gov User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.171 Safari/537.36 Accept: / | csrftoken=ahVYVcKiocwRkM2ev8WZZeDtlmO2lYsj; expires=Wed Feb 4 18:14:48 2026; path=/; domain=.fecfile.fec.gov; max-age=31449481; secure Cookies set via JavaScript do not have an associated HTTP response header. |
Solution:
The general recommendation is to send "secure" cookies to client only using secure connection.
May involve editing or working with django middleware
QA Notes
Developers will present artifact of change for verification
DEV Notes
null
Design
null
See full ticket and images here: FECFILE-2007
The text was updated successfully, but these errors were encountered: