mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-02 18:19:07 +01:00
Restrict updateEnvFile in ConfigPersistence so UPDATE_CHANNEL is only written for supported canonical channels (stable or rc), preventing multiline injection into .env. Keep destination API tokens and SSO settings during POST /api/config/import unless the caller is an instance administrator or holds an instance-wide wildcard API token. Apply tenant outbound destination limits and Apprise CLI restrictions to organization administrator imports before staging any files. Reload and publish restored SSO settings and withdraw stale cached OIDC and SAML services after a default-organization import replaces SSO configuration. Contract-Neutral: Security hardening fix without public contract change
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package apicontext
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/models"
|
|
)
|
|
|
|
// OrganizationContextKey is shared by tenant middleware and domain handlers.
|
|
type OrganizationContextKey string
|
|
|
|
const (
|
|
OrgIDContextKey OrganizationContextKey = "org_id"
|
|
OrgContextKey OrganizationContextKey = "org_object"
|
|
)
|
|
|
|
// OrgID returns the selected tenant or the historical default tenant.
|
|
func OrgID(ctx context.Context) string {
|
|
if id, ok := ctx.Value(OrgIDContextKey).(string); ok {
|
|
return id
|
|
}
|
|
return "default"
|
|
}
|
|
|
|
// Organization returns the selected organization or the default organization.
|
|
func Organization(ctx context.Context) *models.Organization {
|
|
if org, ok := ctx.Value(OrgContextKey).(*models.Organization); ok {
|
|
return org
|
|
}
|
|
return &models.Organization{ID: "default", DisplayName: "Default Organization"}
|
|
}
|
|
|
|
type importKeepsAccessCredentialsKey struct{}
|
|
|
|
// WithImportKeepingAccessCredentials marks a configuration import admitted for
|
|
// a caller who may not issue API tokens or write SSO configuration, so the
|
|
// import must leave both as the destination has them.
|
|
func WithImportKeepingAccessCredentials(ctx context.Context) context.Context {
|
|
return context.WithValue(ctx, importKeepsAccessCredentialsKey{}, true)
|
|
}
|
|
|
|
// ImportKeepsAccessCredentials reports whether the transfer boundary marked
|
|
// this import with WithImportKeepingAccessCredentials.
|
|
func ImportKeepsAccessCredentials(ctx context.Context) bool {
|
|
kept, _ := ctx.Value(importKeepsAccessCredentialsKey{}).(bool)
|
|
return kept
|
|
}
|