snapshot of https://github.com/ory/kratos.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
This commit is contained in:
59
selfservice/flow/internal_context.go
Normal file
59
selfservice/flow/internal_context.go
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package flow
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/tidwall/sjson"
|
||||
|
||||
"github.com/ory/kratos/identity"
|
||||
"github.com/ory/x/sqlxx"
|
||||
)
|
||||
|
||||
// InternalContextKeyCourierBaseURL is the key under which recovery and
|
||||
// verification flows stash the base URL captured at flow init. Email
|
||||
// senders read it back at courier-send time to build the link domain. The
|
||||
// key is top-level (not strategy-scoped) because the value is flow-wide.
|
||||
const InternalContextKeyCourierBaseURL = "courier_base_url"
|
||||
|
||||
// InternalContextKeyRequestBaseURL is the key under which login,
|
||||
// registration, and settings flows stash the customer-facing base URL
|
||||
// captured at flow init. The OIDC/SAML strategy reads it back at
|
||||
// provider-submit time and embeds it in the encrypted state, so the
|
||||
// social-sign-in callback can be redirected onto the host the user
|
||||
// started on (Ory CLI/Tunnel, custom domain) instead of the bare
|
||||
// projects.oryapis host the IdP redirects to. The key is top-level (not
|
||||
// strategy-scoped) because the value is flow-wide.
|
||||
const InternalContextKeyRequestBaseURL = "request_base_url"
|
||||
|
||||
func PrefixInternalContextKey(t identity.CredentialsType, suffix string) string {
|
||||
return string(t) + "_" + suffix
|
||||
}
|
||||
|
||||
// SetRequestBaseURL stashes the base URL captured at flow init (by a
|
||||
// proxy-aware middleware, via x.WithBaseURL on the request context) into
|
||||
// the flow's InternalContext under InternalContextKeyRequestBaseURL. Empty
|
||||
// input is a no-op (preserves the "no rewrite" path). Inputs longer than
|
||||
// 8192 bytes are rejected so a pathological header cannot bloat the row —
|
||||
// the same implicit ceiling the courier base URL uses.
|
||||
func SetRequestBaseURL(f InternalContexter, baseURL string) error {
|
||||
if baseURL == "" || len(baseURL) > 8192 {
|
||||
return nil
|
||||
}
|
||||
f.EnsureInternalContext()
|
||||
out, err := sjson.SetBytes(f.GetInternalContext(), InternalContextKeyRequestBaseURL, baseURL)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
f.SetInternalContext(sqlxx.JSONRawMessage(out))
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetRequestBaseURL returns the base URL captured at flow init, or the
|
||||
// empty string when nothing was captured (the OIDC/SAML callback then does
|
||||
// not rewrite — matching plain projects.oryapis traffic).
|
||||
func GetRequestBaseURL(f InternalContexter) string {
|
||||
return gjson.GetBytes(f.GetInternalContext(), InternalContextKeyRequestBaseURL).String()
|
||||
}
|
||||
Reference in New Issue
Block a user