Skip to content

Commit

Permalink
Add a basic security Hurl suite (#64)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Jan 3, 2025
1 parent 8a42b0d commit 40453e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/server/resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace sourcemeta::registry {

// TODO: Turn this into a "safe" path join that prevents going out of the base
auto path_join(const std::filesystem::path &base,
const std::filesystem::path &path) -> std::filesystem::path {
if (path.is_absolute()) {
Expand Down Expand Up @@ -60,13 +59,8 @@ auto resolver(const sourcemeta::jsontoolkit::URI &server_base_url,
}

assert(uri.path().has_value());
// TODO: Prevent a malicious client from requesting a JSON file outside
// the schema directory by using relative paths
const auto schema_path{path_join(schema_base_directory, uri.path().value())};
if (!std::filesystem::exists(schema_path) ||
// Dot files are not permitted to be schemas, as we use them
// for internal purposes
schema_path.stem().string().starts_with('.')) {
if (!std::filesystem::exists(schema_path)) {
return std::nullopt;
}

Expand Down
5 changes: 5 additions & 0 deletions test/e2e/common/security.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GET {{base}}/../generated/index.json
HTTP 404

GET {{base}}/doc/../../generated/index.json
HTTP 404

0 comments on commit 40453e6

Please sign in to comment.