Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ts/packages/agentSdk/src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export type SerializedError = {
export type ActionResultError = {
error: string;
fallbackToReasoning?: boolean | undefined;
// Stable machine-readable code for callers that need policy or retry
// decisions without parsing the display message.
errorCode?: string | undefined;
// Whether the caller may safely retry after changing the action.
retryable?: boolean | undefined;
// True when the failed action may already have changed external state.
mayHaveSideEffects?: boolean | undefined;
// Rich display to show in place of the plain `error` text (e.g. setup
// instructions with a config snippet, which need markdown to survive
// rendering). Optional — clients fall back to `error` when absent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{
"id": "dev-route-02",
"category": "dev-actions-routing",
"description": "PowerShell schema family includes the root flow schema",
"description": "PowerShell schema family includes the files namespace",
"required": true,
"setup": {
"requiredFlows": ["listFiles"]
Expand All @@ -51,7 +51,7 @@
"disposition": {
"status": "handled",
"path": "action",
"schemas": ["powershell"]
"schemas": ["powershell.powershell-files"]
}
}
}
Expand Down
82 changes: 62 additions & 20 deletions ts/packages/agents/powershell/scripts/scriptHost.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,44 @@ param(

$ErrorActionPreference = 'Stop'

function Remove-TrailingDirectorySeparator {
param([string]$Path)

$root = [System.IO.Path]::GetPathRoot($Path)
if ($Path.Equals($root, [System.StringComparison]::OrdinalIgnoreCase)) {
return $root
}
return $Path.TrimEnd('\', '/')
}

function Get-CanonicalFileSystemPath {
param([string]$Path)

$fullPath = [System.IO.Path]::GetFullPath($Path)
if (Test-Path -LiteralPath $fullPath) {
$item = Get-Item -LiteralPath $fullPath -Force
return Remove-TrailingDirectorySeparator $item.FullName
}

$missingSegments = [System.Collections.Generic.List[string]]::new()
$existingPath = $fullPath
while (-not (Test-Path -LiteralPath $existingPath)) {
$leaf = Split-Path -Leaf $existingPath
$parent = Split-Path -Parent $existingPath
if (-not $leaf -or -not $parent -or $parent -eq $existingPath) {
throw "Unable to resolve path '$Path'."
}
$missingSegments.Insert(0, $leaf)
$existingPath = $parent
}

$canonicalPath = (Get-Item -LiteralPath $existingPath -Force).FullName
foreach ($segment in $missingSegments) {
$canonicalPath = Join-Path $canonicalPath $segment
}
return Remove-TrailingDirectorySeparator ([System.IO.Path]::GetFullPath($canonicalPath))
}

try {
$allowedCmdlets = $AllowedCmdletsJson | ConvertFrom-Json
$params = $ParametersJson | ConvertFrom-Json
Expand All @@ -50,9 +88,11 @@ try {
$expandedAllowedPaths = @()
foreach ($ap in $AllowedPaths) {
try {
$expandedAllowedPaths += $ExecutionContext.InvokeCommand.ExpandString($ap)
$expandedPath = $ExecutionContext.InvokeCommand.ExpandString($ap)
$expandedAllowedPaths += Get-CanonicalFileSystemPath $expandedPath
} catch {
$expandedAllowedPaths += $ap
Write-Error "Invalid allowed path '$ap': $_"
exit 1
}
}

Expand All @@ -73,26 +113,28 @@ try {
continue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot highlighted a concern here that Start-Process accepts executable names and resolves them through PATH. So executables outside of allowedPaths can still be run here for example :

 Path = "powershell.exe"  with  Arguments = "-NoProfile -Command Get-Process"

It suggests explicitly declaring which action parameters represent paths. This will allow executable parameters to be resolved to canonical paths and validated, while parameters representing things like library names can properly skipped and not marked as a path.

}

$isValidPath = $false
try { $isValidPath = Test-Path $val -IsValid } catch { }
if ($isValidPath) {
$resolvedPath = $null
try { $resolvedPath = (Resolve-Path $val -ErrorAction SilentlyContinue).Path } catch {}
if ($resolvedPath) {
$pathAllowed = $false
foreach ($ap in $expandedAllowedPaths) {
if ($resolvedPath -like "$ap*") {
$pathAllowed = $true
break
}
}
# ENFORCEMENT: Block execution if path not allowed
if (-not $pathAllowed) {
Write-Error "Path access denied: '$resolvedPath' is not in allowedPaths. Allowed paths: $($expandedAllowedPaths -join ', ')"
exit 1
}
try {
$resolvedPath = Get-CanonicalFileSystemPath $val

@jebrans jebrans Aug 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work for URL's in data like

{
    actionName: "writeFile",
    parameters: {
        path: "C:\\Users\\me\\notes.txt",
        content: "https://example.test/api",
    },
}

} catch {
Write-Error "Invalid path parameter '$($prop.Name)': $_"
exit 1
}
$pathAllowed = $false
foreach ($ap in $expandedAllowedPaths) {
if (
$resolvedPath.Equals($ap, [System.StringComparison]::OrdinalIgnoreCase) -or
$resolvedPath.StartsWith("$ap\", [System.StringComparison]::OrdinalIgnoreCase) -or
$resolvedPath.StartsWith("$ap/", [System.StringComparison]::OrdinalIgnoreCase)
) {
$pathAllowed = $true
break
}
}
# ENFORCEMENT: Block execution if path not allowed
if (-not $pathAllowed) {
Write-Error "Path access denied: '$resolvedPath' is not in allowedPaths. Allowed paths: $($expandedAllowedPaths -join ', ')"
exit 1
}
}
}
}
Expand Down
Loading
Loading