Add compliange page base URL in context and use it to validate redirect URLs
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -23,8 +23,9 @@ import (
|
||||
type ctxKey struct{ name string }
|
||||
|
||||
var (
|
||||
compliancePageKey = &ctxKey{name: "compliance_page"}
|
||||
complianceMembershipKey = &ctxKey{name: "compliance_membership"}
|
||||
compliancePageKey = &ctxKey{name: "compliance_page"}
|
||||
complianceMembershipKey = &ctxKey{name: "compliance_membership"}
|
||||
compliancePageBaseURLKey = &ctxKey{name: "compliance_page_base_url"}
|
||||
)
|
||||
|
||||
func CompliancePageFromContext(ctx context.Context) *coredata.TrustCenter {
|
||||
@@ -36,3 +37,8 @@ func ComplianceMembershipFromContext(ctx context.Context) *coredata.TrustCenterA
|
||||
membership, _ := ctx.Value(complianceMembershipKey).(*coredata.TrustCenterAccess)
|
||||
return membership
|
||||
}
|
||||
|
||||
func CompliancePageBaseURLFromContext(ctx context.Context) *string {
|
||||
page, _ := ctx.Value(compliancePageBaseURLKey).(*string)
|
||||
return page
|
||||
}
|
||||
|
||||
@@ -23,12 +23,13 @@ import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/vektah/gqlparser/v2/gqlerror"
|
||||
"go.gearno.de/kit/httpserver"
|
||||
"go.probo.inc/probo/pkg/baseurl"
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
"go.probo.inc/probo/pkg/server/gqlutils"
|
||||
"go.probo.inc/probo/pkg/trust"
|
||||
)
|
||||
|
||||
func NewIDMiddleware(trustSvc *trust.Service) func(next http.Handler) http.Handler {
|
||||
func NewIDMiddleware(trustSvc *trust.Service, baseURL string) func(next http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -56,6 +57,10 @@ func NewIDMiddleware(trustSvc *trust.Service) func(next http.Handler) http.Handl
|
||||
return
|
||||
}
|
||||
|
||||
baseURL := baseurl.MustParse(baseURL).AppendPath("/trust/" + id.String()).MustString()
|
||||
ctx = context.WithValue(ctx, compliancePageBaseURLKey, &baseURL)
|
||||
r = r.WithContext(ctx)
|
||||
|
||||
if !compliancePage.Active {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
@@ -85,6 +90,10 @@ func NewIDMiddleware(trustSvc *trust.Service) func(next http.Handler) http.Handl
|
||||
return
|
||||
}
|
||||
|
||||
baseURL := baseurl.MustParse(baseURL).AppendPath("/trust/" + value).MustString()
|
||||
ctx = context.WithValue(ctx, compliancePageBaseURLKey, &baseURL)
|
||||
r = r.WithContext(ctx)
|
||||
|
||||
if compliancePage.Active {
|
||||
ctx = context.WithValue(ctx, compliancePageKey, compliancePage)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/99designs/gqlgen/graphql"
|
||||
"github.com/vektah/gqlparser/v2/gqlerror"
|
||||
@@ -55,6 +56,19 @@ func NewSNIMiddleware(trustSvc *trust.Service) func(next http.Handler) http.Hand
|
||||
return
|
||||
}
|
||||
|
||||
baseURL := &url.URL{
|
||||
Host: r.Host,
|
||||
Path: r.URL.Path,
|
||||
Scheme: "https",
|
||||
}
|
||||
|
||||
ctx = context.WithValue(
|
||||
ctx,
|
||||
compliancePageBaseURLKey,
|
||||
new(baseURL.String()),
|
||||
)
|
||||
r = r.WithContext(ctx)
|
||||
|
||||
if compliancePage.Active {
|
||||
ctx = context.WithValue(ctx, compliancePageKey, compliancePage)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
|
||||
Reference in New Issue
Block a user