Skip to content

Added support for a static RelayState value #48

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ Provides a SAML SP authentication proxy for backend web services
The path to the X509 public certificate PEM file for this SP (env SAML_PROXY_SP_CERT_PATH) (default "saml-auth-proxy.cert")
-sp-key-path path
The path to the X509 private key PEM file for this SP (env SAML_PROXY_SP_KEY_PATH) (default "saml-auth-proxy.key")
-static-relay-state string
A fixed RelayState value, such as a short URL. Will be trimmed to 80 characters to conform with SAML. The default generates random bytes that are Base64
encoded. (env SAML_PROXY_STATIC_RELAY_STATE)
-version
show version and exit
```
Expand Down
1 change: 1 addition & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ type Config struct {
AllowIdpInitiated bool `usage:"If set, allows for IdP initiated authentication flow"`
AuthVerifyPath string `default:"/_verify" usage:"Path under BaseUrl that will respond with a 200 when authenticated"`
Debug bool `usage:"Enable debug logs"`
StaticRelayState string `usage:"A fixed RelayState value, such as a short URL. Will be trimmed to 80 characters to conform with SAML. The default generates random bytes that are Base64 encoded."`
}
15 changes: 13 additions & 2 deletions server/request_tracker_cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ import (
type CookieRequestTracker struct {
samlsp.CookieRequestTracker

CookieDomain string
CookieDomain string
StaticRelayState string
}

func minOfInts(x, y int) int {
if x < y {
return x
} else {
return y
}
}

// Source: https://github.com/crewjam/saml/blob/5e0ffd290abf0be7dfd4f8279e03a963071544eb/samlsp/request_tracker_cookie.go#L28-58
Expand All @@ -28,7 +37,9 @@ func (t CookieRequestTracker) TrackRequest(w http.ResponseWriter, r *http.Reques
URI: r.URL.String(),
}

if t.RelayStateFunc != nil {
if t.StaticRelayState != "" {
trackedRequest.Index = t.StaticRelayState[0:minOfInts(80, len(t.StaticRelayState))]
} else if t.RelayStateFunc != nil {
relayState := t.RelayStateFunc(w, r)
if relayState != "" {
trackedRequest.Index = relayState
Expand Down
3 changes: 2 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func Start(ctx context.Context, logger *zap.Logger, cfg *Config) error {
URL: *rootUrl,
Key: keyPair.PrivateKey.(*rsa.PrivateKey),
}, &middleware.ServiceProvider),
CookieDomain: cookieDomain,
CookieDomain: cookieDomain,
StaticRelayState: cfg.StaticRelayState,
}
cookieSessionProvider := samlsp.DefaultSessionProvider(samlOpts)
cookieSessionProvider.Name = cfg.CookieName
Expand Down