Skip to content

Commit 6a13421

Browse files
committed
Catch bad http headers in requests to YDB monitoring
[skip ci]
1 parent 1fa5b08 commit 6a13421

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

ydb/core/mon/async_http_mon.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ class THttpMonLegacyActorRequest : public TActorBootstrapped<THttpMonLegacyActor
200200
if (Event->Get()->Request->Method == "OPTIONS") {
201201
return ReplyOptionsAndPassAway();
202202
}
203+
try {
204+
Container.GetHeaders();
205+
} catch (const yexception& exception) {
206+
return ReplyBadRequestAndPassAway(exception.what());
207+
}
203208
Become(&THttpMonLegacyActorRequest::StateFunc);
204209
if (ActorMonPage->Authorizer) {
205210
NActors::IEventHandle* handle = ActorMonPage->Authorizer(SelfId(), Container);
@@ -247,6 +252,18 @@ class THttpMonLegacyActorRequest : public TActorBootstrapped<THttpMonLegacyActor
247252
PassAway();
248253
}
249254

255+
void ReplyBadRequestAndPassAway(const TString& message) {
256+
NHttp::THttpIncomingRequestPtr request = Event->Get()->Request;
257+
TStringBuilder response;
258+
response << "HTTP/1.1 400 Bad Request\r\n"
259+
<< "Content-Type: text/plain\r\n"
260+
<< "Connection: close\r\n"
261+
<< "\r\n"
262+
<< message << "\r\n";
263+
ReplyWith(request->CreateResponseString(response));
264+
PassAway();
265+
}
266+
250267
void ReplyUnathorizedAndPassAway(const TString& error = {}) {
251268
NHttp::THttpIncomingRequestPtr request = Event->Get()->Request;
252269
NHttp::THeaders headers(request->Headers);

0 commit comments

Comments
 (0)