-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Dump HTTP request headers #13992
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
Dump HTTP request headers #13992
Conversation
src/httpserver.cpp
Outdated
RequestMethodString(hreq->GetRequestMethod()), hreq->GetURI(), hreq->GetPeer().ToString()); | ||
|
||
for (auto i : hreq->GetHeaders()) { | ||
LogPrint(BCLog::HTTP, " %s: %s\n", i.first, i.second); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should redact authorization header?
Output example when using
Output example when running the test framework:
|
Concept ACK Perhaps some sanitization or escaping is needed on the adversary controlled input before printing/logging to make sure we’re not opening up to log injection, etc? |
af855e2
to
8d416e4
Compare
@practicalswift Added a commit that only dumps headers if the request is valid (authorized and method is known). |
src/httpserver.cpp
Outdated
@@ -239,6 +239,12 @@ static void http_request_cb(struct evhttp_request* req, void* arg) | |||
return; | |||
} | |||
|
|||
// Dump headers if request is valid | |||
LogPrint(BCLog::HTTP, "Request headers:\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should avoid doing this if !LogAcceptCategory(BCLog::HTTP)
, no need for the overhead to copy the headers when the result is ignored
agree that string sanitizing is very important to prevent manipulation with escape codes etc. EDIT dumping the |
f0e8c1d
to
1a4af64
Compare
@laanwj right, I asked it above #13992 (comment). |
Thinking of it, I'm not sure this is worth the added code and complexity. |
1a4af64
to
88f1c9d
Compare
Updated to redact authorization header (added Agree with @laanwj and I'm going to close this unless there is a strong reason to keep it. |
@@ -646,6 +670,11 @@ HTTPRequest::RequestMethod HTTPRequest::GetRequestMethod() | |||
} | |||
} | |||
|
|||
bool EqualHeaders(const std::string& h1, const std::string& h2) | |||
{ | |||
return evutil_ascii_strcasecmp(h1.c_str(), h2.c_str()) == 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for relying on libevent
in this function? If not I suggest doing this without relying on third-party code by introducing the required locale independent string helper functions in-tree. That would perhaps also allow us to reduce the number of know locale dependence problems listed here: https://github.com/bitcoin/bitcoin/blob/master/test/lint/lint-locale-dependence.sh#L4
Note to reviewers: This pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
Hey @promag I was looking at this PR when you closed it. I agree with @laanwj and you that a web debugging proxy is the right tool for inspecting HTTP requests. If the PR was still open and you where leaning towards implementing it, I would have suggested to extract the dump headers implementation and make it a freestanding utility function. But more importantly, IMO the changes where non-const member functions have been changed to |
Yeah I was going to cherry pick that. Thanks for reviewing. |
No description provided.