Verify Crisp website ownership before connecting
Crisp is a managed (Model B) connector: Probo holds one plugin token server-side and each connection carries only a Website ID. Nothing stops one organization from entering another organization's Website ID, so prove control of the website before creating the connection. Probo derives a per-(organization, website) verification code as an HMAC over the token secret and exposes it through a new crispVerificationCode query. The customer pastes it into the Probo plugin's per-website settings; at connect time the resolver reads the setting back through the managed plugin token and requires a constant-time match before any row is written. The managed key and plugin ID come from bootstrap, so the connector stays hidden until the deployment configures them. The settings fetch is injected so the create-time gate's branch wiring is unit-tested (mismatch and not-subscribed reject, internal errors stay generic, a matching code passes), and the managed-versus-client key resolution is covered too. Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
@@ -36,17 +36,16 @@ func (r *mutationResolver) CreateAPIKeyConnector(ctx context.Context, input type
|
||||
return nil, err
|
||||
}
|
||||
|
||||
apiKey, err := r.resolveAPIKeyConnectorCredential(input.Provider, input.APIKey)
|
||||
if err != nil {
|
||||
return nil, gqlutils.Invalid(ctx, err)
|
||||
}
|
||||
|
||||
req := probo.CreateConnectorRequest{
|
||||
OrganizationID: input.OrganizationID,
|
||||
Provider: input.Provider,
|
||||
Protocol: coredata.ConnectorProtocolAPIKey,
|
||||
Connection: &connector.APIKeyConnection{
|
||||
APIKey: input.APIKey,
|
||||
Header: r.providerRegistry.APIKeyHeader(input.Provider),
|
||||
BasicAuth: r.providerRegistry.APIKeyUsesBasicAuth(input.Provider),
|
||||
BasicAuthUserPass: r.providerRegistry.APIKeyUsesBasicAuthUserPass(input.Provider),
|
||||
Scheme: r.providerRegistry.APIKeyAuthScheme(input.Provider),
|
||||
},
|
||||
Connection: r.newAPIKeyConnection(input.Provider, apiKey),
|
||||
}
|
||||
|
||||
raw, err := apiKeyConnectorSettings(input)
|
||||
@@ -56,6 +55,16 @@ func (r *mutationResolver) CreateAPIKeyConnector(ctx context.Context, input type
|
||||
|
||||
req.RawSettings = raw
|
||||
|
||||
// Crisp (ManagedAPIKey) requires proof the organization controls the Crisp
|
||||
// website before the connection is created; every other API-key provider is
|
||||
// unaffected. Runs after settings validation and before any write, so a
|
||||
// failed check leaves no row.
|
||||
if input.Provider == coredata.ConnectorProviderCrisp {
|
||||
if err := r.verifyCrispOwnership(ctx, input); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
cnnctr, err := r.probo.Connectors.Create(ctx, scope, req)
|
||||
if err != nil {
|
||||
if errors.Is(err, coredata.ErrResourceAlreadyExists) {
|
||||
|
||||
Reference in New Issue
Block a user