From 5879805e4ba06b9d1a1969e842422baaa6d38280 Mon Sep 17 00:00:00 2001 From: Michael Mandrus <41969079+mmandrus@users.noreply.github.com> Date: Tue, 25 Oct 2022 20:16:10 -0400 Subject: [PATCH] PublicDashboards: Fix unsafe code snippets (#57641) * return an error if we can't extract queries from a panel * check for null or undefined --- pkg/services/publicdashboards/models/models.go | 4 ++++ pkg/services/publicdashboards/service/query.go | 2 +- .../features/dashboard/services/PublicDashboardDataSource.ts | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/services/publicdashboards/models/models.go b/pkg/services/publicdashboards/models/models.go index 5051599df82..f773e763f83 100644 --- a/pkg/services/publicdashboards/models/models.go +++ b/pkg/services/publicdashboards/models/models.go @@ -61,6 +61,10 @@ var ( Reason: "bad Request", StatusCode: 400, } + ErrNoPanelQueriesFound = PublicDashboardErr{ + Reason: "failed to extract queries from panel", + StatusCode: 400, + } ) type PublicDashboard struct { diff --git a/pkg/services/publicdashboards/service/query.go b/pkg/services/publicdashboards/service/query.go index 0ab3ac969b9..46fd6589cb7 100644 --- a/pkg/services/publicdashboards/service/query.go +++ b/pkg/services/publicdashboards/service/query.go @@ -131,7 +131,7 @@ func (pd *PublicDashboardServiceImpl) GetQueryDataResponse(ctx context.Context, } if len(metricReq.Queries) == 0 { - return nil, nil + return nil, models.ErrNoPanelQueriesFound } anonymousUser := buildAnonymousUser(ctx, dashboard) diff --git a/public/app/features/dashboard/services/PublicDashboardDataSource.ts b/public/app/features/dashboard/services/PublicDashboardDataSource.ts index 7d299bba9b0..c57d8b7effe 100644 --- a/public/app/features/dashboard/services/PublicDashboardDataSource.ts +++ b/public/app/features/dashboard/services/PublicDashboardDataSource.ts @@ -59,7 +59,7 @@ export class PublicDashboardDataSource extends DataSourceApi