fix(task): accept plugin-owned repository providers on task create (#3005)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Carlos Florencio <carlosmflorencio@gmail.com>
This commit is contained in:
Corey Fogg
2026-08-25 09:40:32 +00:00
committed by GitHub
parent 4a9f0ad030
commit e11768cbea
4 changed files with 78 additions and 1 deletions
@@ -148,3 +148,68 @@ func TestResolveRepositoryRef_TrustedDescriptorRejectsCredentialsAndIncompleteId
t.Fatal("ResolveRepositoryRef() accepted credential-bearing/incomplete descriptor")
}
}
func TestResolveRepositoryRef_BrowserPluginDescriptorKeepsBuiltinHostRejection(t *testing.T) {
svc, _, repo := createTestService(t)
ctx := context.Background()
if err := repo.CreateWorkspace(ctx, &models.Workspace{ID: "ws-1", Name: "Workspace"}); err != nil {
t.Fatalf("CreateWorkspace: %v", err)
}
_, _, _, err := svc.ResolveRepositoryRef(ctx, "ws-1", TaskRepositoryInput{
RemoteURL: "https://forge.example.test/acme/widgets.git",
Provider: "forge",
ProviderHost: "https://forge.example.test",
ProviderRepoID: "42",
ProviderOwner: "acme",
ProviderName: "widgets",
})
if err == nil {
t.Fatal("ResolveRepositoryRef() accepted a browser-supplied plugin descriptor")
}
}
func TestResolveRepositoryRef_TrustedDescriptorRejectsForeignCloneOrigin(t *testing.T) {
svc, _, repo := createTestService(t)
ctx := context.Background()
if err := repo.CreateWorkspace(ctx, &models.Workspace{ID: "ws-1", Name: "Workspace"}); err != nil {
t.Fatalf("CreateWorkspace: %v", err)
}
// An owned provider must not carry a clone URL off its own origin: the
// clone would present that provider's managed credentials to another host.
_, _, _, err := svc.ResolveRepositoryRef(ctx, "ws-1", TaskRepositoryInput{
RemoteURL: "https://attacker.example.test/acme/widgets.git",
Provider: "bitbucket",
ProviderHost: "https://bitbucket.org",
ProviderRepoID: "{7c445c85}",
ProviderOwner: "acme",
ProviderName: "widgets",
TrustedProviderDescriptor: true,
})
if err == nil {
t.Fatal("ResolveRepositoryRef() accepted a trusted descriptor outside the provider origin")
}
}
func TestResolveRepositoryRef_BuiltinProviderKeepsCoreParsePath(t *testing.T) {
svc, _, repo := createTestService(t)
ctx := context.Background()
if err := repo.CreateWorkspace(ctx, &models.Workspace{ID: "ws-1", Name: "Workspace"}); err != nil {
t.Fatalf("CreateWorkspace: %v", err)
}
repositoryID, _, _, err := svc.ResolveRepositoryRef(ctx, "ws-1", TaskRepositoryInput{
RemoteURL: "https://github.com/acme/api", Provider: "github",
})
if err != nil {
t.Fatalf("ResolveRepositoryRef() unexpected error: %v", err)
}
stored, err := repo.GetRepository(ctx, repositoryID)
if err != nil {
t.Fatalf("GetRepository: %v", err)
}
if stored.RemoteURL != "https://github.com/acme/api.git" {
t.Fatalf("stored remote_url = %q, want the parser-canonicalized URL", stored.RemoteURL)
}
}
@@ -49,6 +49,11 @@ type TaskRepositoryInput struct {
// provider descriptor already authorized by the plugin host. It is never
// accepted from REST/MCP JSON; callers must still supply every identity and
// exact credential-free clone URL field above.
//
// A descriptor that arrives without this marker uses the normal built-in
// resolver. Plugin descriptors must come through the authenticated plugin
// Host Tasks.Create path, which sets this marker only after validating the
// active plugin's provider ownership and clone origin.
TrustedProviderDescriptor bool `json:"-"`
}
@@ -19,6 +19,7 @@ import (
"go.uber.org/zap"
"github.com/kandev/kandev/internal/events"
"github.com/kandev/kandev/internal/repoclone"
"github.com/kandev/kandev/internal/steptelemetry"
"github.com/kandev/kandev/internal/task/models"
taskrepo "github.com/kandev/kandev/internal/task/repository"
@@ -943,6 +944,9 @@ func (s *Service) resolveRepoInput(ctx context.Context, workspaceID string, repo
return s.resolveRepoInputID(ctx, workspaceID, repositoryID, baseBranch)
}
// Only the plugin Host Tasks.Create path can set this internal marker.
// REST, WebSocket, and MCP callers must go through the built-in resolver;
// they cannot assert ownership of a plugin descriptor in request data.
if repoInput.TrustedProviderDescriptor {
return s.resolveTrustedRemoteRepository(ctx, workspaceID, repoInput, baseBranch)
}
@@ -1286,6 +1290,9 @@ func validateTrustedRemoteRepository(input TaskRepositoryInput) error {
if _, err := validateProviderScope(input.ProviderScope); err != nil {
return errors.New("trusted remote repository provider_scope is invalid")
}
if err := repoclone.ValidateHTTPSCloneOrigin(input.RemoteURL, input.ProviderHost); err != nil {
return fmt.Errorf("trusted remote repository clone origin: %w", err)
}
parsed, _, err := normalizeRemoteRepositoryURL(input.RemoteURL)
if err != nil {
return err
+1 -1
View File
@@ -170,7 +170,7 @@ ui: # optional native frontend plugin
| `actions[].key` | yes\* | string | Unique non-empty action key, used at `POST /api/plugins/{id}/actions/{key}`. |
| `actions[].scope` | yes\* | `workspace` \| `task` \| `repository` | Resource selector the host authorizes. A task-scoped invocation may additionally name one repository attached to that verified task. Use the canonical field name `scope`; `resource_scope` is only a legacy read-compatibility spelling and must not be authored. |
| `actions[].max_body_bytes` | yes\* | int | Maximum size of the decoded untrusted `body`, from 1 through 1,048,576 bytes. The whole HTTP envelope has a slightly larger hard cap. |
| `repository_providers` | no | string[] | Provider IDs this plugin owns while active. An active provider can register native repository discovery/URL inspection and may supply transient Git credentials. Duplicate ownership is rejected. |
| `repository_providers` | no | string[] | Provider IDs this plugin owns while active. An active provider can register native repository discovery/URL inspection and may supply transient Git credentials. Native task creation must use the authenticated plugin task-create path so the plugin reauthorizes the repository descriptor before Host Tasks.Create. Duplicate ownership is rejected. |
| `reference_sources[]` | no | object[] | Dynamic composer-reference source. Each entry declares `source`, `provider`, `kind`, `display_name`, and `kind_label`; `order` is optional. Candidate identity is not trusted: Kandev reauthorizes the canonical reference when it is submitted. |
| `auth_providers[]` | no | object[] | Login buttons this plugin contributes to the pre-auth login screen (needs `capabilities.auth`). Each is `{ id, display_name, initiate }`, where `initiate` names one of the plugin's `webhooks[].key` values; the button navigates to that webhook, which 302-redirects to the IdP. Surfaced anonymously in the boot payload as `auth.ssoProviders`. |
| `config_schema` | no | object | JSON-Schema-like object driving the settings form at **Settings > Plugins > `<plugin>`** (`GET /api/plugins/{id}/config` and `PATCH /api/plugins/{id}`). See "Config schema validation and secret fields" below. |