Skip to content

Commit 8e2d470

Browse files
committed
Used random file in a hidi folder to address security concerns.
1 parent 7aac03f commit 8e2d470

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,15 @@ internal static async Task ShowOpenApiDocument(string openapi, string csdl, stri
515515
// If output is null, create a HTML file in the user's temporary directory
516516
if (output == null)
517517
{
518-
var tempPath = Path.GetTempPath();
518+
var tempPath = Path.GetTempPath() + "/hidi/";
519+
if(!File.Exists(tempPath))
520+
{
521+
Directory.CreateDirectory(tempPath);
522+
}
523+
524+
var fileName = Path.GetRandomFileName();
519525

520-
output = new FileInfo(Path.Combine(tempPath, "apitree.html"));
526+
output = new FileInfo(Path.Combine(tempPath, fileName + ".html"));
521527
using (var file = new FileStream(output.FullName, FileMode.Create))
522528
{
523529
using var writer = new StreamWriter(file);
@@ -526,7 +532,7 @@ internal static async Task ShowOpenApiDocument(string openapi, string csdl, stri
526532
logger.LogTrace("Created Html document with diagram ");
527533

528534
// Launch a browser to display the output html file
529-
var process = new Process();
535+
using var process = new Process();
530536
process.StartInfo.FileName = output.FullName;
531537
process.StartInfo.UseShellExecute = true;
532538
process.Start();

test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public void ReturnOpenApiConvertSettingsWhenSettingsFileIsProvided(string filePa
8080
}
8181
}
8282

83+
8384
[Fact]
8485
public void ShowCommandGeneratesMermaidDiagramAsMarkdown()
8586
{
@@ -130,6 +131,22 @@ public async Task ShowCommandGeneratesMermaidMarkdownFileWithMermaidDiagram()
130131
Assert.Contains("graph LR", output);
131132
}
132133

134+
[Fact]
135+
public void InvokeTransformCommand()
136+
{
137+
var rootCommand = Program.CreateRootCommand();
138+
var args = new string[] { "transform", "-d", ".\\UtilityFiles\\SampleOpenApi.yml", "-o", "sample.json" };
139+
var parseResult = rootCommand.Parse(args);
140+
var handler = rootCommand.Subcommands.Where(c => c.Name == "transform").First().Handler;
141+
var context = new InvocationContext(parseResult);
142+
143+
handler.Invoke(context);
144+
145+
var output = File.ReadAllText("sample.json");
146+
Assert.NotEmpty(output);
147+
}
148+
149+
133150
[Fact]
134151
public void InvokeShowCommand()
135152
{

0 commit comments

Comments
 (0)