Skip to content

Commit

Permalink
Catch bad http headers in requests to YDB monitoring
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
jepett0 committed Feb 2, 2024
1 parent 1fa5b08 commit 6a13421
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ydb/core/mon/async_http_mon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ class THttpMonLegacyActorRequest : public TActorBootstrapped<THttpMonLegacyActor
if (Event->Get()->Request->Method == "OPTIONS") {
return ReplyOptionsAndPassAway();
}
try {
Container.GetHeaders();
} catch (const yexception& exception) {
return ReplyBadRequestAndPassAway(exception.what());
}
Become(&THttpMonLegacyActorRequest::StateFunc);
if (ActorMonPage->Authorizer) {
NActors::IEventHandle* handle = ActorMonPage->Authorizer(SelfId(), Container);
Expand Down Expand Up @@ -247,6 +252,18 @@ class THttpMonLegacyActorRequest : public TActorBootstrapped<THttpMonLegacyActor
PassAway();
}

void ReplyBadRequestAndPassAway(const TString& message) {
NHttp::THttpIncomingRequestPtr request = Event->Get()->Request;
TStringBuilder response;
response << "HTTP/1.1 400 Bad Request\r\n"
<< "Content-Type: text/plain\r\n"
<< "Connection: close\r\n"
<< "\r\n"
<< message << "\r\n";
ReplyWith(request->CreateResponseString(response));
PassAway();
}

void ReplyUnathorizedAndPassAway(const TString& error = {}) {
NHttp::THttpIncomingRequestPtr request = Event->Get()->Request;
NHttp::THeaders headers(request->Headers);
Expand Down

0 comments on commit 6a13421

Please sign in to comment.