aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Efimov <xeno@ydb.tech>2025-04-24 16:55:35 +0200
committerGitHub <noreply@github.com>2025-04-24 16:55:35 +0200
commitf767409d63b812cf773a4be335454a323fe494dd (patch)
treed61221a8b319478abaa14843ea68bd0a616d6726
parent92112970f70e509e460170843edec96913044290 (diff)
downloadydb-f767409d63b812cf773a4be335454a323fe494dd.tar.gz
better usage of AllowOrigin setting (#17670)
-rw-r--r--ydb/core/driver_lib/run/run.cpp1
-rw-r--r--ydb/core/mon/mon.cpp15
-rw-r--r--ydb/core/mon/mon.h5
-rw-r--r--ydb/core/viewer/viewer.cpp11
4 files changed, 28 insertions, 4 deletions
diff --git a/ydb/core/driver_lib/run/run.cpp b/ydb/core/driver_lib/run/run.cpp
index 77090167a6c..f537e3397f9 100644
--- a/ydb/core/driver_lib/run/run.cpp
+++ b/ydb/core/driver_lib/run/run.cpp
@@ -477,6 +477,7 @@ void TKikimrRunner::InitializeMonitoring(const TKikimrRunConfig& runConfig, bool
if (securityConfig.MonitoringAllowedSIDsSize() > 0) {
monConfig.AllowedSIDs.assign(securityConfig.GetMonitoringAllowedSIDs().begin(), securityConfig.GetMonitoringAllowedSIDs().end());
}
+ monConfig.AllowOrigin = appConfig.GetMonitoringConfig().GetAllowOrigin();
if (ModuleFactories && ModuleFactories->MonitoringFactory) {
Monitoring = ModuleFactories->MonitoringFactory(std::move(monConfig), appConfig);
diff --git a/ydb/core/mon/mon.cpp b/ydb/core/mon/mon.cpp
index c1739366b72..de7d94312f3 100644
--- a/ydb/core/mon/mon.cpp
+++ b/ydb/core/mon/mon.cpp
@@ -16,6 +16,7 @@
#include <library/cpp/lwtrace/mon/mon_lwtrace.h>
#include <ydb/library/actors/core/probes.h>
#include <ydb/core/base/monitoring_provider.h>
+#include <ydb/core/util/wildcard.h>
#include <library/cpp/monlib/service/pages/version_mon_page.h>
#include <library/cpp/monlib/service/pages/mon_page.h>
@@ -403,7 +404,19 @@ public:
type = "application/json";
}
NHttp::THeaders headers(request->Headers);
- TString origin = TString(headers["Origin"]);
+ TString allowOrigin = AppData()->Mon->GetConfig().AllowOrigin;
+ TString requestOrigin = TString(headers["Origin"]);
+ TString origin;
+ if (allowOrigin) {
+ if (IsMatchesWildcards(requestOrigin, allowOrigin)) {
+ origin = requestOrigin;
+ } else {
+ Send(Event->Sender, new NHttp::TEvHttpProxy::TEvHttpOutgoingResponse(request->CreateResponseBadRequest("Invalid CORS origin")));
+ return PassAway();
+ }
+ } else if (requestOrigin) {
+ origin = requestOrigin;
+ }
if (origin.empty()) {
origin = "*";
}
diff --git a/ydb/core/mon/mon.h b/ydb/core/mon/mon.h
index c413a59954a..e27fece9595 100644
--- a/ydb/core/mon/mon.h
+++ b/ydb/core/mon/mon.h
@@ -40,6 +40,7 @@ public:
TString Certificate;
ui32 MaxRequestsPerSecond = 0;
TDuration InactivityTimeout = TDuration::Minutes(2);
+ TString AllowOrigin;
};
TMon(TConfig config);
@@ -86,6 +87,10 @@ public:
});
}
+ const TConfig& GetConfig() const {
+ return Config;
+ }
+
protected:
TConfig Config;
TIntrusivePtr<NMonitoring::TIndexMonPage> IndexMonPage;
diff --git a/ydb/core/viewer/viewer.cpp b/ydb/core/viewer/viewer.cpp
index 6e6e4fe14ea..4bd29d8df0c 100644
--- a/ydb/core/viewer/viewer.cpp
+++ b/ydb/core/viewer/viewer.cpp
@@ -729,11 +729,16 @@ IActor* CreateViewer(const TKikimrRunConfig& kikimrRunConfig) {
}
void TViewer::FillCORS(TStringBuilder& stream, const TRequestState& request) {
+ TString requestOrigin = request && request.HasHeader("Origin") ? request.GetHeader("Origin") : TString();
TString origin;
if (AllowOrigin) {
- origin = AllowOrigin;
- } else if (request && request.HasHeader("Origin")) {
- origin = request.GetHeader("Origin");
+ if (IsMatchesWildcards(requestOrigin, AllowOrigin)) {
+ origin = requestOrigin;
+ } else {
+ return; // no CORS headers - no access
+ }
+ } else if (requestOrigin) {
+ origin = requestOrigin;
}
if (origin.empty()) {
origin = "*";