Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a basic security Hurl suite #64

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading