Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For Label value privacy or hacking free, allow usage of Label Header instead of query ( X-Prom-Label-<label name> ) #76

Open
zucher opened this issue Aug 21, 2021 · 2 comments

Comments

@zucher
Copy link

zucher commented Aug 21, 2021

In case of custom parameter usage under Grafana, "Explore" request use directly in request the query param label provided, Hacking the request become possible in that case.

Allowing the Label value passing through http header is not impact by this hack.

Suggestion:
X-Prom-Label-<label name> : xxxx

func (r *routes) enforceLabel(h http.HandlerFunc) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
+		lvalue := req.Header.Get("X-Prom-Label-" + r.label)
+		if lvalue == "" {
+			lvalue = req.URL.Query().Get(r.label)
+		}

		if lvalue == "" {
+			http.Error(w, fmt.Sprintf("Bad request. The %q query parameter or X-Prom-Label-%q header must be provided.", r.label, r.label), http.StatusBadRequest)
			return
		}
		req = req.WithContext(withLabelValue(req.Context(), lvalue))
@zucher
Copy link
Author

zucher commented Aug 24, 2021

Seems specific characters are not supported in header key like _
instead of
X-Prom-Label-

I suggest to use :
X-Prom-Label-Key: xxxx
X-Prom-Label-Value: yyyy

or

X-Prom-Label: xxxx:yyyy

Alternative is to normalize the header name by replacing unexpected characters by other ones and putting all in lower cases

@zucher
Copy link
Author

zucher commented Aug 25, 2021

Final proposition:

func (r *routes) enforceLabel(h http.HandlerFunc) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		normalizedLabel := strings.Replace(r.label, "_", "-", -1)
		lvalue := req.Header.Get("X-Prom-Label-" + normalizedLabel)
		if lvalue == "" {
			lvalue = req.URL.Query().Get(r.label)
		}

		if lvalue == "" {
			http.Error(w, fmt.Sprintf("Bad request. The %q query parameter or \"X-Prom-Label-%s\" header must be provided.", r.label, r.label), http.StatusBadRequest)
			return
		}

and under grafana datasource definition the header should contains "-" instead of "_" if the label contains such info
ex for app_kubernetes_io_name --> X-Prom-Label-app-kubernetes-io-name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant