Skip to content

Commit e77a9b0

Browse files
committed
Sanitize paths
1 parent 554569e commit e77a9b0

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/services/Elastic.Changelog/Bundling/ChangelogBundlingService.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,11 @@ public async Task<bool> BundleChangelogs(IDiagnosticsCollector collector, Bundle
375375
{
376376
// Resolution order: bundle.output_directory → input.OutputDirectory (programmatic override)
377377
// → bundle.directory → CWD
378-
var outputDir = config.Bundle.OutputDirectory
378+
var outputDir = (config.Bundle.OutputDirectory
379379
?? input.OutputDirectory
380380
?? config.Bundle.Directory
381-
?? _fileSystem.Directory.GetCurrentDirectory();
381+
?? _fileSystem.Directory.GetCurrentDirectory())
382+
.Replace('/', _fileSystem.Path.DirectorySeparatorChar);
382383
outputPath = _fileSystem.Path.Join(outputDir, outputPattern);
383384
}
384385

@@ -418,18 +419,18 @@ public async Task<bool> BundleChangelogs(IDiagnosticsCollector collector, Bundle
418419
};
419420
}
420421

421-
private static BundleChangelogsArguments ApplyConfigDefaults(BundleChangelogsArguments input, ChangelogConfiguration? config)
422+
private BundleChangelogsArguments ApplyConfigDefaults(BundleChangelogsArguments input, ChangelogConfiguration? config)
422423
{
423424
// Apply directory: CLI takes precedence. Only use config when --directory not specified.
424-
var directory = input.Directory ?? config?.Bundle?.Directory ?? Directory.GetCurrentDirectory();
425+
var directory = input.Directory ?? config?.Bundle?.Directory ?? _fileSystem.Directory.GetCurrentDirectory();
425426

426427
if (config?.Bundle == null)
427428
return input with { Directory = directory, LinkAllowRepos = null };
428429

429430
// Apply output default when --output not specified: use bundle.output_directory if set
430431
var output = input.Output;
431432
if (string.IsNullOrWhiteSpace(output) && !string.IsNullOrWhiteSpace(config.Bundle.OutputDirectory))
432-
output = Path.Join(config.Bundle.OutputDirectory, "changelog-bundle.yaml");
433+
output = _fileSystem.Path.Join(config.Bundle.OutputDirectory.Replace('/', _fileSystem.Path.DirectorySeparatorChar), "changelog-bundle.yaml");
433434

434435
// Apply resolve: CLI takes precedence over config. Only use config when CLI did not specify.
435436
var resolve = input.Resolve ?? config.Bundle.Resolve;
@@ -500,13 +501,14 @@ private static BundleChangelogsArguments ApplyConfigDefaults(BundleChangelogsArg
500501
var outputPattern = profileDef.Output
501502
.Replace("{version}", version)
502503
.Replace("{lifecycle}", lifecycle);
503-
var outputDir = config?.Bundle?.OutputDirectory
504+
var outputDir = (config?.Bundle?.OutputDirectory
504505
?? config?.Bundle?.Directory
505-
?? _fileSystem.Directory.GetCurrentDirectory();
506+
?? _fileSystem.Directory.GetCurrentDirectory())
507+
.Replace('/', _fileSystem.Path.DirectorySeparatorChar);
506508
outputPath = _fileSystem.Path.Join(outputDir, outputPattern);
507509
}
508510
else if (string.IsNullOrWhiteSpace(outputPath) && config?.Bundle?.OutputDirectory != null)
509-
outputPath = _fileSystem.Path.Join(config.Bundle.OutputDirectory, "changelog-bundle.yaml");
511+
outputPath = _fileSystem.Path.Join(config.Bundle.OutputDirectory.Replace('/', _fileSystem.Path.DirectorySeparatorChar), "changelog-bundle.yaml");
510512

511513
return new BundlePlanResult
512514
{

src/services/Elastic.Changelog/Uploading/ChangelogUploadService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public async Task<bool> Upload(IDiagnosticsCollector collector, ChangelogUploadA
9999

100100
internal IReadOnlyList<UploadTarget> DiscoverUploadTargets(IDiagnosticsCollector collector, string changelogDir)
101101
{
102+
var rootDir = _fileSystem.DirectoryInfo.New(changelogDir);
103+
102104
var yamlFiles = _fileSystem.Directory.GetFiles(changelogDir, "*.yaml", SearchOption.TopDirectoryOnly)
103105
.Concat(_fileSystem.Directory.GetFiles(changelogDir, "*.yml", SearchOption.TopDirectoryOnly))
104106
.ToList();
@@ -107,6 +109,13 @@ internal IReadOnlyList<UploadTarget> DiscoverUploadTargets(IDiagnosticsCollector
107109

108110
foreach (var filePath in yamlFiles)
109111
{
112+
var fileInfo = _fileSystem.FileInfo.New(filePath);
113+
if (SymlinkValidator.ValidateFileAccess(fileInfo, rootDir) is { } accessError)
114+
{
115+
collector.EmitWarning(filePath, $"Skipping: {accessError}");
116+
continue;
117+
}
118+
110119
var products = ReadProductsFromFragment(filePath);
111120
if (products.Count == 0)
112121
{

0 commit comments

Comments
 (0)