Skip to content

Commit 5d7b5f5

Browse files
return CORS to bad 403 response (#20720)
1 parent 94310f1 commit 5d7b5f5

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

ydb/mvp/oidc_proxy/extension_whoami.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ void TExtensionWhoami::PatchResponse(NJson::TJsonValue& json, NJson::TJsonValue&
4545
TString messageOverride;
4646
NJson::TJsonValue* outJson = nullptr;
4747

48+
SetCORS(Context->Params->Request, Context->Params->HeadersOverride.Get());
49+
Context->Params->HeadersOverride->Set("Content-Type", "application/json; charset=utf-8");
50+
4851
if (json.Has(USER_SID) && json.Has(ORIGINAL_USER_TOKEN)) {
4952
statusOverride = "200";
5053
messageOverride = "OK";
@@ -62,7 +65,7 @@ void TExtensionWhoami::PatchResponse(NJson::TJsonValue& json, NJson::TJsonValue&
6265
}
6366
outJson = &errorJson;
6467
}
65-
Context->Params->HeadersOverride->Set("Content-Type", "application/json; charset=utf-8");
68+
6669
TStringStream content;
6770
NJson::WriteJson(&content, outJson, {
6871
.FloatToStringMode = EFloatToStringMode::PREC_NDIGITS,

ydb/mvp/oidc_proxy/oidc_proxy_ut.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,8 +1532,12 @@ Y_UNIT_TEST_SUITE(Mvp) {
15321532
{
15331533
TStringBuilder response;
15341534
response << "HTTP/1.1 " << status << "\r\n"
1535-
<< "Connection: close\r\n"
1536-
<< "Content-Type: " << contentType << "\r\n";
1535+
<< "Connection: close\r\n"
1536+
<< "Content-Type: " << contentType << "\r\n"
1537+
<< "Access-Control-Allow-Origin: *\r\n"
1538+
<< "Access-Control-Allow-Credentials: true\r\n"
1539+
<< "Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n"
1540+
<< "Access-Control-Allow-Headers: Authorization, Content-Type\r\n";
15371541
for (const auto& [key, value] : extraHeaders) {
15381542
response << key << ": " << value << "\r\n";
15391543
}
@@ -1623,6 +1627,10 @@ Y_UNIT_TEST_SUITE(Mvp) {
16231627
NJson::TJsonValue json;
16241628
NHttp::THeaders headers(outgoing->Response->Headers);
16251629

1630+
UNIT_ASSERT(headers.Has("Access-Control-Allow-Credentials"));
1631+
UNIT_ASSERT(headers.Has("Access-Control-Allow-Headers"));
1632+
UNIT_ASSERT(headers.Has("Access-Control-Allow-Methods"));
1633+
UNIT_ASSERT(headers.Has("Access-Control-Allow-Origin"));
16261634
if (!outgoing->Response->Status.StartsWith("3") && outgoing->Response->Status != "404") {
16271635
UNIT_ASSERT(headers.Has("Content-Type"));
16281636
UNIT_ASSERT_STRINGS_EQUAL(headers.Get("Content-Type").NextTok(';'), "application/json");

0 commit comments

Comments
 (0)