Files
probo/pkg/server/api/trust/v1/nda_resolvers.go
Bryan Frimin f20c3d73d2 Verify signature ownership in esign accept/record-event flows
Any self-provisioned trust center visitor could accept another
visitor's NDA signature or inject audit-trail events into it by
supplying its GID, since AcceptSignature and RecordEvent trusted the
client-supplied signature ID without checking it belonged to the
caller (GHSA-22xj-f767-ppw6). SignerEmail/ActorEmail are always
derived from the verified session identity, never client input, so
comparing them against the signature's stored SignerEmail in
pkg/esign/service.go closes the hole at its root without touching the
resolver-level authorization already in place elsewhere.

Adds an e2e regression test that self-provisions two trust center
visitors through the real magic-link flow and confirms one cannot
touch the other's signature.

Signed-off-by: Bryan Frimin <bryan@probo.com>
2026-07-09 10:27:22 +02:00

168 lines
5.5 KiB
Go

package trust_v1
// This file will be automatically regenerated based on the schema, any resolver
// implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.93
import (
"context"
"errors"
"time"
"go.gearno.de/kit/log"
"go.probo.inc/probo/pkg/coredata"
"go.probo.inc/probo/pkg/esign"
"go.probo.inc/probo/pkg/server/api/authn"
"go.probo.inc/probo/pkg/server/api/clientip"
"go.probo.inc/probo/pkg/server/api/compliancepage"
"go.probo.inc/probo/pkg/server/api/trust/v1/schema"
"go.probo.inc/probo/pkg/server/api/trust/v1/types"
"go.probo.inc/probo/pkg/server/gqlutils"
)
// AcceptElectronicSignature is the resolver for the acceptElectronicSignature field.
func (r *mutationResolver) AcceptElectronicSignature(ctx context.Context, input types.AcceptElectronicSignatureInput) (*types.AcceptElectronicSignaturePayload, error) {
var (
identity = authn.IdentityFromContext(ctx)
httpReq = gqlutils.HTTPRequestFromContext(ctx)
compliancePage = compliancepage.CompliancePageFromContext(ctx)
scope = coredata.NewScopeFromObjectID(compliancePage.OrganizationID)
)
signerIP := clientip.Extract(httpReq)
signature, err := r.esign.AcceptSignature(
ctx,
scope,
&esign.AcceptSignatureRequest{
SignatureID: input.SignatureID,
SignerFullName: identity.FullName,
SignerEmail: identity.EmailAddress,
SignerIPAddr: signerIP,
SignerUA: httpReq.UserAgent(),
},
)
if err != nil {
if errors.Is(err, esign.ErrElectronicSignatureNotFound) {
return nil, gqlutils.NotFoundf(ctx, "electronic signature %q not found", input.SignatureID)
}
if errors.Is(err, esign.ErrSignatureAccessDenied) {
return nil, gqlutils.Forbiddenf(ctx, "cannot accept electronic signature")
}
r.logger.ErrorCtx(ctx, "cannot accept electronic signature", log.Error(err))
return nil, gqlutils.Internal(ctx)
}
return &types.AcceptElectronicSignaturePayload{
Signature: types.NewElectronicSignature(signature),
}, nil
}
// RecordSigningEvent is the resolver for the recordSigningEvent field.
func (r *mutationResolver) RecordSigningEvent(ctx context.Context, input types.RecordSigningEventInput) (*types.RecordSigningEventPayload, error) {
var (
identity = authn.IdentityFromContext(ctx)
httpReq = gqlutils.HTTPRequestFromContext(ctx)
compliancePage = compliancepage.CompliancePageFromContext(ctx)
scope = coredata.NewScopeFromObjectID(compliancePage.OrganizationID)
)
actorIP := clientip.Extract(httpReq)
if err := r.esign.RecordEvent(
ctx,
scope,
&esign.RecordEventRequest{
SignatureID: input.SignatureID,
EventType: input.EventType,
EventSource: coredata.ElectronicSignatureEventSourceClient,
ActorEmail: identity.EmailAddress,
ActorIPAddr: actorIP,
ActorUA: httpReq.UserAgent(),
},
); err != nil {
if errors.Is(err, esign.ErrElectronicSignatureNotFound) {
return nil, gqlutils.NotFoundf(ctx, "electronic signature %q not found", input.SignatureID)
}
if errors.Is(err, esign.ErrSignatureAccessDenied) {
return nil, gqlutils.Forbiddenf(ctx, "cannot record signing event")
}
r.logger.ErrorCtx(ctx, "cannot record signing event", log.Error(err))
return nil, gqlutils.Internal(ctx)
}
return &types.RecordSigningEventPayload{Success: true}, nil
}
// FileURL is the resolver for the fileUrl field.
func (r *nonDisclosureAgreementResolver) FileURL(ctx context.Context, obj *types.NonDisclosureAgreement) (string, error) {
compliancePage := compliancepage.CompliancePageFromContext(ctx)
if identity := authn.IdentityFromContext(ctx); identity != nil && r.esign != nil {
scope := coredata.NewScopeFromObjectID(compliancePage.OrganizationID)
trustService := r.trust
access, err := trustService.TrustCenterAccesses.GetAccess(ctx, scope, compliancePage.ID, identity.ID)
if err == nil && access.ElectronicSignatureID != nil {
fileURL, err := r.esign.GenerateSignatureFileURL(ctx, *access.ElectronicSignatureID, 15*time.Minute)
if err == nil {
return fileURL, nil
}
r.logger.ErrorCtx(ctx, "cannot generate signature file URL, falling back to original NDA", log.Error(err))
}
}
scope := coredata.NewScopeFromObjectID(compliancePage.OrganizationID)
trustService := r.trust
fileURL, err := trustService.TrustCenters.GenerateNDAFileURL(ctx, scope, compliancePage.ID, 15*time.Minute)
if err != nil {
return "", gqlutils.Internal(ctx)
}
return fileURL, nil
}
// ViewerSignature is the resolver for the viewerSignature field.
func (r *nonDisclosureAgreementResolver) ViewerSignature(ctx context.Context, obj *types.NonDisclosureAgreement) (*types.ElectronicSignature, error) {
identity := authn.IdentityFromContext(ctx)
if identity == nil {
return nil, nil
}
compliancePage := compliancepage.CompliancePageFromContext(ctx)
scope := coredata.NewScopeFromObjectID(compliancePage.OrganizationID)
trustService := r.trust
access, err := trustService.TrustCenterAccesses.GetAccess(ctx, scope, compliancePage.ID, identity.ID)
if err != nil {
return nil, nil
}
if access.ElectronicSignatureID == nil {
return nil, nil
}
sig, err := r.esign.GetSignatureByID(ctx, scope, *access.ElectronicSignatureID)
if err != nil {
return nil, nil
}
return types.NewElectronicSignature(sig), nil
}
// NonDisclosureAgreement returns schema.NonDisclosureAgreementResolver implementation.
func (r *Resolver) NonDisclosureAgreement() schema.NonDisclosureAgreementResolver {
return &nonDisclosureAgreementResolver{r}
}
type nonDisclosureAgreementResolver struct{ *Resolver }