Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <iostream>
#include <nlohmann/json.hpp>
#include <regex>
#include <sstream>

#include "data_message.h"
Expand Down Expand Up @@ -204,6 +205,17 @@ void TripleAssembler::generateTriplesFromNode(const Node& node, const SchemaType
// Split node data point into object and data elements
const auto [object_elements, data_element] = extractObjectsAndDataElements(node.getName());

// Validate each component against an identifier pattern to guard against SPARQL injection
static const std::regex valid_id{R"([A-Za-z][A-Za-z0-9_]*)"};
for (const auto& elem : object_elements) {
if (!std::regex_match(elem, valid_id)) {
throw std::runtime_error("Invalid node name component: " + elem);
}
}
if (!std::regex_match(data_element, valid_id)) {
throw std::runtime_error("Invalid node name component: " + data_element);
}

const auto queries = model_config_->getQueriesTripleAssemblerHelper().getQueries();
TripleAssemblerHelper::QueryPair query_pair;
if (queries.find(msg_schema_type) != queries.end()) {
Expand Down