Skip to content

Commit 33a3e55

Browse files
authored
.Net: [BREAKING] Upgrade Prompty.Core to 2.0.0-beta.3 to resolve NU1903 vulnerability (#14169)
## Motivation and Context CI (`dotnet-build-and-test`) currently fails repo-wide on **NU1903**: `Prompty.Core` `0.2.3-beta` has a known high severity advisory [GHSA-wxhm-2mq7-7697](GHSA-wxhm-2mq7-7697) (path traversal in `${file:...}` reference expansion). The build treats the audit as an error (`--warnaserror`), so this blocks every .NET PR. The advisory is fixed in `Prompty.Core` **2.0.0-beta.2+**. That release is a significant rewrite: it targets **net9.0 only** and ships a new `.prompty` spec and API. There is no intermediate 0.x fix, so resolving the advisory requires this upgrade. ## Description Upgrades `Prompty.Core` `0.2.3-beta` → `2.0.0-beta.3` and adapts Semantic Kernel to the 2.0 surface. - **Package**: bump `Prompty.Core` in `Directory.Packages.props`; remove the `Scriban` workaround reference (2.0 no longer depends on it). - **Target frameworks**: retarget `Functions.Prompty` to `net10.0` only. The fixed package is net9.0-only, so `net8.0` and `netstandard2.0` can no longer be supported. - **Loader migration** (`KernelFunctionPrompty`): - Text input: `FrontmatterParser.Parse` + `Prompty.Load`. - File input: secure `PromptyLoader.Load` with `AllowedFileRoots` scoped to the prompty file's directory, so `${file:...}` references are confined (the fix for the advisory). - Parse failures are normalized to `ArgumentException` to preserve the input-validation contract. - **Test data + tests**: migrate the `.prompty` files to the 2.0 spec (`apiType`, list-form `inputs`, renamed `options`) and update `PromptyTests` accordingly. - **Samples**: update the `Concepts` inline templates to the 2.0 spec. ## ⚠️ Breaking changes `Microsoft.SemanticKernel.Prompty` is a preview (`-beta`) package. This change: - **Drops `net8.0` and `netstandard2.0`** support (now `net10.0` only). - Requires `.prompty` files to use the **2.0 spec** (`model.apiType`, `model.provider`, `connection.kind`, `inputs`/`outputs` as lists, renamed `model.options`). v1 files are not auto-migrated. See the [Prompty v1→v2 migration guide](https://www.prompty.ai/migration/). - No longer surfaces the following, which are not part of the 2.0 model: input/output `json_schema`, connection `service_id`, and arbitrary `model.options` passthrough beyond the strongly typed set. ## Validation - `Functions.Prompty.UnitTests`: **22/22 pass** (Release, `--warnaserror`). - `Functions.Prompty` and `Concepts` build clean, **no NU1903**. - `dotnet format --verify-no-changes` clean on changed projects. - Behavior coherence: rendered prompt output for the `Concepts` samples is **byte-for-byte identical** to the previously published package, and the samples were run end-to-end against a live model with the expected results. ## Contribution Checklist - [x] The code builds clean without errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) - [x] All unit tests pass, and I have added/updated tests where possible - [x] I didn't break anyone 😄
1 parent c781da1 commit 33a3e55

10 files changed

Lines changed: 133 additions & 182 deletions

File tree

‎dotnet/Directory.Packages.props‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@
106106
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.15.1" />
107107
<PackageVersion Include="PdfPig" Version="0.1.13" />
108108
<PackageVersion Include="Pinecone.Client" Version="3.1.0" />
109-
<PackageVersion Include="Prompty.Core" Version="0.2.3-beta" />
110-
<PackageVersion Include="Scriban" Version="7.2.5" />
109+
<PackageVersion Include="Prompty.Core" Version="2.0.0-beta.3" />
111110
<PackageVersion Include="PuppeteerSharp" Version="20.2.5" />
112111
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="10.0.2" />
113112
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.16.0" />

‎dotnet/samples/Concepts/PromptTemplates/PromptyFunction.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public async Task InlineFunctionAsync()
2525
authors:
2626
- ????
2727
model:
28-
api: chat
28+
apiType: chat
2929
---
3030
system:
3131
You are a helpful assistant who knows all about cities in the USA
@@ -56,7 +56,7 @@ public async Task InlineFunctionWithVariablesAsync()
5656
authors:
5757
- ????
5858
model:
59-
api: chat
59+
apiType: chat
6060
---
6161
system:
6262
You are an AI agent for the Contoso Outdoors products retailer. As the agent, you answer questions briefly, succinctly,
@@ -121,7 +121,7 @@ public async Task RenderPromptAsync()
121121
authors:
122122
- ????
123123
model:
124-
api: chat
124+
apiType: chat
125125
---
126126
What is Seattle?
127127
""";

‎dotnet/src/Functions/Functions.Prompty.UnitTests/PromptyTests.cs‎

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public void ChatPromptyShouldSupportCreatingOpenAIExecutionSettingsWithJsonObjec
9797
Assert.Equal(0, executionSettings.Temperature);
9898
Assert.Equal(1.0, executionSettings.TopP);
9999
Assert.Null(executionSettings.StopSequences);
100-
Assert.Equal("{\"type\":\"json_object\"}", executionSettings.ResponseFormat?.ToString());
101100
Assert.Null(executionSettings.TokenSelectionBiases);
102101
Assert.Equal(3000, executionSettings.MaxTokens);
103102
Assert.Null(executionSettings.Seed);
@@ -226,25 +225,41 @@ public void ItFailsToParseAnEmptyHeader()
226225
---
227226
Abc
228227
""")]
229-
[InlineData("""
230-
---a
231-
name: SomePrompt
232-
---
233-
Abc
234-
""")]
235228
[InlineData("""
236229
---
237230
name: SomePrompt
238231
---b
239232
Abc
240233
""")]
241-
public void ItRequiresStringSeparatorPlacement(string prompt)
234+
public void ItToleratesLenientFrontmatterSeparatorPlacement(string prompt)
242235
{
243236
// Arrange
244237
Kernel kernel = new();
245238

246-
// Act / Assert
247-
Assert.Throws<ArgumentException>(() => kernel.CreateFunctionFromPrompty(prompt));
239+
// Act - Prompty 2.0 tolerates surrounding whitespace and trailing characters on the
240+
// frontmatter separators, so these templates are parsed rather than rejected. This is
241+
// not a security-relevant relaxation, so no stricter validation is imposed on top.
242+
var kernelFunction = kernel.CreateFunctionFromPrompty(prompt);
243+
244+
// Assert
245+
Assert.NotNull(kernelFunction);
246+
Assert.Equal("SomePrompt", kernelFunction.Name);
247+
}
248+
249+
[Fact]
250+
public void ItThrowsForMalformedFrontmatterYaml()
251+
{
252+
// Arrange
253+
Kernel kernel = new();
254+
255+
// Act / Assert - a non-separator opening line ("---a") leaves invalid YAML in the
256+
// frontmatter, which surfaces as an ArgumentException.
257+
Assert.Throws<ArgumentException>(() => kernel.CreateFunctionFromPrompty("""
258+
---a
259+
name: SomePrompt
260+
---
261+
Abc
262+
"""));
248263
}
249264

250265
[Fact]
@@ -342,7 +357,8 @@ public void ItCreatesInputVariablesOnlyWhenNoneAreExplicitlySet()
342357
---
343358
name: MyPrompt
344359
inputs:
345-
question:
360+
- name: question
361+
kind: string
346362
description: What is the color of the sky?
347363
---
348364
{{a}} {{b}} {{c}}
@@ -366,20 +382,14 @@ public void ItShouldLoadExecutionSettings()
366382
name: SomePrompt
367383
description: This is the description.
368384
model:
369-
api: chat
370-
connection:
371-
type: azure_openai_beta
385+
apiType: chat
372386
options:
373-
logprobs: true
374-
top_logprobs: 2
375-
top_p: 1.0
376-
user: Bob
377-
stop_sequences:
387+
temperature: 0.5
388+
topP: 1.0
389+
maxOutputTokens: 1000
390+
stopSequences:
378391
- END
379392
- COMPLETE
380-
token_selection_biases:
381-
1: 2
382-
3: 4
383393
---
384394
Abc---def
385395
""";
@@ -393,12 +403,10 @@ public void ItShouldLoadExecutionSettings()
393403
Assert.NotNull(executionSettings);
394404
var openaiExecutionSettings = OpenAIPromptExecutionSettings.FromExecutionSettings(executionSettings);
395405
Assert.NotNull(openaiExecutionSettings);
396-
Assert.True(openaiExecutionSettings.Logprobs);
397-
Assert.Equal(2, openaiExecutionSettings.TopLogprobs);
406+
Assert.Equal(0.5, openaiExecutionSettings.Temperature);
398407
Assert.Equal(1.0, openaiExecutionSettings.TopP);
399-
Assert.Equal("Bob", openaiExecutionSettings.User);
408+
Assert.Equal(1000, openaiExecutionSettings.MaxTokens);
400409
Assert.Equal(["END", "COMPLETE"], openaiExecutionSettings.StopSequences);
401-
Assert.Equal(new Dictionary<int, int>() { { 1, 2 }, { 3, 4 } }, openaiExecutionSettings.TokenSelectionBiases);
402410
}
403411

404412
[Fact]
@@ -442,32 +450,6 @@ public void ItShouldCreateFunctionFromPromptYamlContainingRelativeFileReferences
442450
Assert.Equal("gpt-35-turbo", defaultExecutionSetting.ModelId);
443451
}
444452

445-
[Fact]
446-
public void JsonSchemaTest()
447-
{
448-
// Arrange
449-
Kernel kernel = new();
450-
var chatPromptyPath = Path.Combine("TestData", "chat.prompty");
451-
var promptyTemplate = File.ReadAllText(chatPromptyPath);
452-
453-
// Act
454-
var kernelFunction = kernel.CreateFunctionFromPrompty(promptyTemplate);
455-
456-
// Assert
457-
var firstName = kernelFunction.Metadata.Parameters.First(p => p.Name == "firstName");
458-
Assert.NotNull(firstName);
459-
Assert.NotNull(firstName.Schema);
460-
Assert.Equal("{\"type\":\"string\"}", firstName.Schema.ToString());
461-
var answer = kernelFunction.Metadata.Parameters.First(p => p.Name == "answer");
462-
Assert.NotNull(answer);
463-
Assert.NotNull(answer.Schema);
464-
Assert.Equal("{\"type\":\"object\",\"properties\":{\"answer\":{\"type\":\"string\"},\"citations\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"format\":\"uri\"}}},\"required\":[\"answer\",\"citations\"],\"additionalProperties\":false}", answer.Schema.ToString());
465-
var other = kernelFunction.Metadata.Parameters.First(p => p.Name == "other");
466-
Assert.NotNull(other);
467-
Assert.NotNull(other.Schema);
468-
Assert.Equal("{\"type\":\"object\",\"properties\":{\"answer\":{\"type\":\"string\"},\"citations\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"format\":\"uri\"}}},\"required\":[\"answer\",\"citations\"],\"additionalProperties\":\"false\"}", other.Schema.ToString());
469-
}
470-
471453
private sealed class EchoTextGenerationService : ITextGenerationService
472454
{
473455
public IReadOnlyDictionary<string, object?> Attributes { get; } = new Dictionary<string, object?>();

‎dotnet/src/Functions/Functions.Prompty.UnitTests/TestData/chat.prompty‎

Lines changed: 16 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,91 +8,31 @@ metadata:
88
- basic
99
model:
1010
id: gpt-35-turbo
11-
api: chat
12-
connection:
13-
type: azure_openai
14-
api_version: 2023-07-01-preview
15-
options:
16-
tools_choice: auto
17-
tools:
18-
- id: test
19-
type: function
20-
description: test function
21-
options:
22-
parameters:
23-
- name: location
24-
type: string
25-
required: true
26-
description: The city and state or city and country, e.g. San Francisco, CA or Tokyo, Japan
11+
apiType: chat
2712
inputs:
28-
firstName:
29-
type: string
13+
- name: firstName
14+
kind: string
3015
default: User
31-
sample: April
3216
description: The first name of the customer
33-
json_schema:
34-
type: string
35-
lastName:
36-
type: string
37-
sample: Kwong
17+
- name: lastName
18+
kind: string
3819
required: true
39-
strict: false
4020
description: The last name of the customer
41-
json_schema:
42-
type: string
43-
question:
44-
type: string
45-
description: The question to answer
21+
- name: question
22+
kind: string
4623
required: true
47-
json_schema:
48-
type: string
49-
answer:
50-
type: object
51-
description: Some count
24+
description: The question to answer
25+
- name: answer
26+
kind: object
5227
required: true
5328
description: The answer with citations
54-
json_schema: |
55-
{
56-
"type": "object",
57-
"properties": {
58-
"answer": {
59-
"type": "string"
60-
},
61-
"citations": {
62-
"type": "array",
63-
"items": {
64-
"type": "string",
65-
"format": "uri"
66-
}
67-
}
68-
},
69-
"required": [
70-
"answer",
71-
"citations"
72-
],
73-
"additionalProperties": false
74-
}
75-
other:
76-
type: object
29+
- name: other
30+
kind: object
7731
required: true
78-
description: Property with JSON schema
79-
json_schema:
80-
type: object
81-
properties:
82-
answer:
83-
type: string
84-
citations:
85-
type: array
86-
items:
87-
type: string
88-
format: uri
89-
required:
90-
- answer
91-
- citations
92-
additionalProperties: false
32+
description: Property with additional context
9333
outputs:
94-
work:
95-
type: object
34+
- name: work
35+
kind: object
9636
description: The thing to output
9737
---
9838
system:
@@ -146,4 +86,4 @@ would go well with the items found above. Be brief and concise and use appropria
14686
{% for item in history %}
14787
{{item.role}}:
14888
{{item.content}}
149-
{% endfor %}
89+
{% endfor %}

‎dotnet/src/Functions/Functions.Prompty.UnitTests/TestData/chatJsonObject.prompty‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@ metadata:
66
- markwallace
77
tags:
88
- basic
9-
model:
9+
model:
1010
id: gpt-4o
11-
api: chat
12-
connection:
13-
type: azure_openai
14-
azure_deployment: gpt-4o
11+
apiType: chat
1512
options:
1613
temperature: 0.0
17-
max_tokens: 3000
18-
top_p: 1.0
19-
response_format:
20-
type: json_object
14+
maxOutputTokens: 3000
15+
topP: 1.0
2116
---
2217
system:
2318
You are a classifier agent that should know classify a problem into Easy/Medium/Hard based on the problem description.
@@ -27,4 +22,4 @@ your response should be in a json format with the following structure:
2722
}
2823

2924
user:
30-
{{question}}
25+
{{question}}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
---
22
name: prompty_with_no_execution_setting
33
description: prompty without execution setting
44
metadata:
@@ -7,6 +7,8 @@ metadata:
77
tags:
88
- basic
99
inputs:
10-
prompt: dummy
10+
- name: prompt
11+
kind: string
12+
default: dummy
1113
---
12-
{{prompt}}
14+
{{prompt}}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
{
2-
"api": "chat",
2+
"apiType": "chat",
33
"id": "gpt-35-turbo",
4-
"connection": {
5-
"type": "azure_openai",
6-
"api_version": "2023-07-01-preview"
7-
},
84
"options": {
95
"temperature": 0.5
106
}
117
}
12-

‎dotnet/src/Functions/Functions.Prompty.UnitTests/TestData/relativeFileReference.prompty‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
---
22
name: TestRelativeFileReference
33
description: A test prompt for relative file references
44
metadata:

‎dotnet/src/Functions/Functions.Prompty/Functions.Prompty.csproj‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<!-- THIS PROPERTY GROUP MUST COME FIRST -->
44
<AssemblyName>Microsoft.SemanticKernel.Prompty</AssemblyName>
55
<RootNamespace>$(AssemblyName)</RootNamespace>
6-
<TargetFrameworks>net10.0;net8.0;netstandard2.0</TargetFrameworks>
6+
<TargetFrameworks>net10.0</TargetFrameworks>
77
<VersionSuffix>beta</VersionSuffix>
88
<NoWarn>$(NoWarn);CA1812</NoWarn>
99
</PropertyGroup>
@@ -19,8 +19,6 @@
1919
<ProjectReference Include="..\..\Extensions\PromptTemplates.Liquid\PromptTemplates.Liquid.csproj" />
2020
<ProjectReference Include="..\..\SemanticKernel.Core\SemanticKernel.Core.csproj" />
2121
<PackageReference Include="Prompty.Core" />
22-
<!-- Adding Scriban directly to use latest version number to avoid a vulnerability issue. Can be removed later once Prompty.Core references an updated version -->
23-
<PackageReference Include="Scriban" />
2422
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
2523
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" />
2624
</ItemGroup>

0 commit comments

Comments
 (0)