Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Project and workspace APIs should reject paths with . or .. segments #80

Description

@alexrp

var path = "src";
if (root.TryGetProperty("path"u8, out var pathProp))
{
if (pathProp.ValueKind != JsonValueKind.String)
Error("'path' property, if present, must be a string.");
path = Path.TrimEndingDirectorySeparator(pathProp.GetString()!);
if (Path.IsPathFullyQualified(path))
Error("'path' property, if present, must be relative.");
// TODO: It would be good to verify that the path does not contain any . or .. segments.
}

var paths = ImmutableDictionary<ModulePath, string>.Empty;
if (root.TryGetProperty("paths"u8, out var pathsProp))
{
if (pathsProp.ValueKind != JsonValueKind.Object)
Error("'paths' property, if present, must be an object.");
foreach (var prop in pathsProp.EnumerateObject())
{
if (!ModulePath.TryCreate(prop.Name, out var modPath))
Error($"Module path '{prop.Name}' is invalid.");
if (paths.ContainsKey(modPath))
Error($"Module path '{prop.Name}' has multiple entries.");
var value = prop.Value;
if (value.ValueKind != JsonValueKind.String)
Error($"Directory path for module path '{prop.Name}' must be a string.");
var dir = Path.TrimEndingDirectorySeparator(value.GetString()!);
if (Path.IsPathFullyQualified(dir))
Error($"Directory path for module path '{prop.Name}' must be relative.");
// TODO: It would be good to verify that the path does not contain any . or .. segments.
paths = paths.SetItem(modPath, dir);
}
}

internal static bool IsValidPath(string path)
{
Check.NullOrWhiteSpace(path);
// TODO: It would be good to verify that the path does not contain any . or .. segments.
return !Path.IsPathFullyQualified(path) && Path.GetExtension(path) == ".cel";
}

Activity

  1. added
    state: approved
    area: tooling
    on May 2, 2023
  2. added this to the v1.0 milestone on May 2, 2023
  3. self-assigned this
    on May 2, 2023
  4. alexrp commented on May 19, 2023

    @alexrp
    SponsorMemberAuthor

    This is trivial enough on Unix, I think. I just don't know if Windows (with its insane complexity around paths) has any gotchas here...

  5. removed their assignment
    on Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: toolingstate: approved

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions