Repository navigation
[bug fix] aitools: validate skill names and file paths in the fetched skills manifest #7722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f5bed94
51002ef
02fa672
eb44fea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * `databricks aitools install`, `update` and `list` now refuse a skills manifest that names a skill or file outside the skills directory, before writing any skill files. A skill whose name or file paths are not portable is skipped with a warning, and `update` keeps its installed copy. ([#7722](https://github.com/databricks/cli/pull/7722)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Cloud = false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
|
|
||
| === a manifest listing a file outside its skill directory fails before any file is written | ||
|
|
||
| >>> DATABRICKS_SKILLS_REF=unsafe-ref [CLI] aitools install --skills-only --scope=global --agents=claude-code | ||
| Installing Databricks skills for Claude Code... | ||
| Using skills version unsafe-ref | ||
| Fetching skills manifest... | ||
| Error: skills manifest names a path outside the skills directory: skill "test-stable" lists file "../../.bashrc" | ||
| No skill files were written. Set DATABRICKS_SKILLS_REF to an earlier release tag from https://github.com/databricks/databricks-agent-skills/releases and re-run 'databricks aitools install --scope=global --agents=claude-code --skills-only', and report the manifest from [DATABRICKS_HOST] at https://github.com/databricks/cli/issues | ||
|
|
||
| >>> DATABRICKS_SKILLS_REF=unsafe-ref [CLI] aitools install --skills-only --scope=global --agents=claude-code --output json | ||
| { | ||
| "scope": "global", | ||
| "agents": [], | ||
| "error": "skills manifest names a path outside the skills directory: skill \"test-stable\" lists file \"../../.bashrc\"", | ||
| "error_category": "MANIFEST_INVALID", | ||
| "recovery": "No skill files were written. Set DATABRICKS_SKILLS_REF to an earlier release tag from https://github.com/databricks/databricks-agent-skills/releases and re-run 'databricks aitools install --scope=global --agents=claude-code --skills-only --output json', and report the manifest from [DATABRICKS_HOST] at https://github.com/databricks/cli/issues." | ||
| } | ||
| no skill files were written | ||
|
|
||
| === a skill with an unportable name is skipped and the others install | ||
|
|
||
| >>> DATABRICKS_SKILLS_REF=unportable-ref [CLI] aitools install --skills-only --scope=global --agents=claude-code | ||
| Installing Databricks skills for Claude Code... | ||
| Using skills version unportable-ref | ||
| Fetching skills manifest... | ||
| Warn: Skipping skill "Test_Unportable": the name is not at most 64 lowercase letters, digits and single hyphens | ||
| Installed 1 skill in [TEST_TMP_DIR]/home/.databricks/aitools/skills. | ||
| test-stable | ||
|
|
||
| === naming the unportable skill with --skills fails | ||
|
|
||
| >>> DATABRICKS_SKILLS_REF=unportable-ref [CLI] aitools install --skills-only --scope=global --agents=claude-code --skills=Test_Unportable --output json | ||
| { | ||
| "scope": "global", | ||
| "agents": [], | ||
| "error": "skill \"Test_Unportable\" cannot be installed: the name is not at most 64 lowercase letters, digits and single hyphens", | ||
| "error_category": "MANIFEST_INVALID", | ||
| "recovery": "No skill files were written. Set DATABRICKS_SKILLS_REF to an earlier release tag from https://github.com/databricks/databricks-agent-skills/releases and re-run 'databricks aitools install --scope=global --agents=claude-code --skills-only --skills=Test_Unportable --output json', and report the manifest from [DATABRICKS_HOST] at https://github.com/databricks/cli/issues." | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Isolate HOME so parallel aitools tests don't race on a shared ~/.databricks. | ||
| sethome home | ||
|
|
||
| title "a manifest listing a file outside its skill directory fails before any file is written" | ||
| musterr trace DATABRICKS_SKILLS_REF=unsafe-ref $CLI aitools install --skills-only --scope=global --agents=claude-code | ||
| musterr trace DATABRICKS_SKILLS_REF=unsafe-ref $CLI aitools install --skills-only --scope=global --agents=claude-code --output json | ||
| if [ -e "$HOME/.databricks/aitools/.bashrc" ] || [ -d "$HOME/.databricks/aitools/skills/test-stable" ]; then | ||
| echo "unexpected: a skill file was written" | ||
| else | ||
| echo "no skill files were written" | ||
| fi | ||
|
|
||
| title "a skill with an unportable name is skipped and the others install" | ||
| trace DATABRICKS_SKILLS_REF=unportable-ref $CLI aitools install --skills-only --scope=global --agents=claude-code | ||
| ls "$HOME/.databricks/aitools/skills" | ||
|
|
||
| title "naming the unportable skill with --skills fails" | ||
| musterr trace DATABRICKS_SKILLS_REF=unportable-ref $CLI aitools install --skills-only --scope=global --agents=claude-code --skills=Test_Unportable --output json |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Mock server replaces raw.githubusercontent.com for manifest + skill files. | ||
| Env.DATABRICKS_SKILLS_BASE_URL = "$DATABRICKS_HOST" | ||
|
|
||
| Ignore = [ | ||
| "home", | ||
| ] | ||
|
|
||
| # A manifest that lists a file outside its skill directory. | ||
| [[Server]] | ||
| Pattern = "GET /unsafe-ref/manifest.json" | ||
| Response.Body = ''' | ||
| { | ||
| "version": "2", | ||
| "updated_at": "2026-01-01T00:00:00Z", | ||
| "skills": { | ||
| "test-stable": { | ||
| "version": "1.0.0", | ||
| "files": ["SKILL.md", "../../.bashrc"], | ||
| "repo_dir": "skills" | ||
| } | ||
| } | ||
| } | ||
| ''' | ||
|
|
||
| # A manifest with one portable skill and one whose name is not in the Agent | ||
| # Skills format. | ||
| [[Server]] | ||
| Pattern = "GET /unportable-ref/manifest.json" | ||
| Response.Body = ''' | ||
| { | ||
| "version": "2", | ||
| "updated_at": "2026-01-01T00:00:00Z", | ||
| "skills": { | ||
| "test-stable": { | ||
| "version": "1.0.0", | ||
| "files": ["SKILL.md"], | ||
| "repo_dir": "skills" | ||
| }, | ||
| "Test_Unportable": { | ||
| "version": "1.0.0", | ||
| "files": ["SKILL.md"], | ||
| "repo_dir": "skills" | ||
| } | ||
| } | ||
| } | ||
| ''' | ||
|
|
||
| [[Server]] | ||
| Pattern = "GET /unportable-ref/skills/test-stable/SKILL.md" | ||
| Response.Body = "test-stable" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -238,6 +238,11 @@ func installRecovery(ctx context.Context, inv installInvocation, err error) stri | |
| return "The skills release this CLI selected is missing. Set DATABRICKS_SKILLS_REF to a release tag from " + skillsReleasesURL + " and re-run " + rerun + ", and report it at " + cliIssuesURL + "." | ||
| case protos.AitoolsErrorCategoryManifestInvalid: | ||
| host := skillsHost(ctx) | ||
| // The manifest arrived and decoded, but lists a path outside the | ||
| // skills directory or a skill in a form it cannot be installed in. | ||
| if _, ok := errors.AsType[*installer.SkillError](err); ok || errors.Is(err, installer.ErrUnsafeManifestPath) { | ||
| return "No skill files were written. Set DATABRICKS_SKILLS_REF to an earlier release tag from " + skillsReleasesURL + " and re-run " + rerun + ", and report the manifest from " + host + " at " + cliIssuesURL + "." | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nice to have]
Add a section with a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] For |
||
| } | ||
| return host + " answered with something that is not a skills manifest (a proxy or captive portal page, or a broken mirror). Check what this machine gets from " + host + ", then re-run " + rerun + "." | ||
| case protos.AitoolsErrorCategorySkillsFetchFailed: | ||
| return downloadRecovery(ctx, inv, ferr) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,9 @@ const ( | |
| ReasonVersionIncompatible = "version-incompatible" | ||
| // ReasonExperimentalSkill: the named skill is experimental and --experimental was not set. | ||
| ReasonExperimentalSkill = "experimental-skill" | ||
| // ReasonUnportableSkill: the manifest lists the skill with a name or file | ||
| // path that is not portable, so it is never installed. | ||
| ReasonUnportableSkill = "unportable-skill" | ||
| ) | ||
|
|
||
| func (e *SkillError) Error() string { | ||
|
|
@@ -76,6 +79,11 @@ const maxFetchBodySize = 1 << 20 | |
| // The command layer classifies it like a manifest that does not parse. | ||
| var ErrManifestTooLarge = fmt.Errorf("skills manifest is larger than %d MiB", maxFetchBodySize>>20) | ||
|
|
||
| // ErrUnsafeManifestPath reports a skills manifest that names a skill or file | ||
| // outside the skills directory. The command layer classifies it like a | ||
| // manifest that does not parse. | ||
| var ErrUnsafeManifestPath = errors.New("skills manifest names a path outside the skills directory") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] The error reads "names a path outside the skills directory", but it also fires for |
||
|
|
||
| // Stages of fetching skills content, recorded on FetchError so a failed | ||
| // release lookup can be told apart from a failed download. | ||
| const ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -259,8 +259,9 @@ func fetchSkillFile(ctx context.Context, ref, repoDir, skillName, filePath strin | |
|
|
||
| // FetchSkillsManifestWithFallback fetches the skills manifest at the given ref. | ||
| // If the ref points to a non-existent tag (not-found error), it falls back to | ||
| // the embedded manifest's skills version. Returns the manifest, the (possibly | ||
| // updated) ref, and any error. | ||
| // the embedded manifest's skills version. A manifest that names a skill or file | ||
| // outside its directory fails with ErrUnsafeManifestPath, whatever the source. | ||
| // Returns the manifest, the (possibly updated) ref, and any error. | ||
| func FetchSkillsManifestWithFallback(ctx context.Context, src ManifestSource, ref string, allowFallback bool) (*Manifest, string, error) { | ||
| tag := strings.TrimPrefix(ref, "v") | ||
| manifest, err := src.FetchManifest(ctx, ref) | ||
|
|
@@ -274,7 +275,13 @@ func FetchSkillsManifestWithFallback(ctx context.Context, src ManifestSource, re | |
| log.Warnf(ctx, "Could not resolve embedded skills version: %v", fbErr) | ||
| } | ||
| } | ||
| return manifest, ref, err | ||
| if err != nil { | ||
| return nil, ref, err | ||
| } | ||
| if err := checkManifestPaths(manifest); err != nil { | ||
| return nil, ref, err | ||
| } | ||
| return manifest, ref, nil | ||
| } | ||
|
|
||
| // installedSkillsRelease returns the newest recorded raw-skills release and | ||
|
|
@@ -549,6 +556,14 @@ func resolveSkills(ctx context.Context, skills map[string]SkillMeta, opts Instal | |
|
|
||
| result := make(map[string]SkillMeta, len(candidates)) | ||
| for name, meta := range candidates { | ||
| if reason := unportableSkill(name, meta.Files); reason != "" { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] The portability check runs before the experimental filter, here and in |
||
| if isSpecific { | ||
| return nil, &SkillError{Skill: name, Reason: ReasonUnportableSkill, Detail: "cannot be installed: " + reason} | ||
| } | ||
| log.Warnf(ctx, "Skipping skill %q: %s", name, reason) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] |
||
| continue | ||
| } | ||
|
|
||
| if meta.IsExperimental() && !opts.IncludeExperimental { | ||
| if isSpecific { | ||
| return nil, &SkillError{Skill: name, Reason: ReasonExperimentalSkill, Detail: "is experimental; use --experimental to install"} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit]
TestClassifyInstallError(line 29) already has a row for every otherSkillErrorreason, and.agents/rules/testing.mdasks for table-driven tests for similar cases. Move this case into that table.