Files
Pulse/internal/api/apicontext/context.go
rcourtman 83f17f12d2 Harden config import authority, tenant limits, SSO reload, and .env
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
2026-11-24 12:28:52 +00:00

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
}