Skip to content

Commit

Permalink
Removed alphanumeric enforcement for node IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Wetlesen committed Jun 28, 2022
1 parent 4c7cb15 commit cf256e2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
12 changes: 10 additions & 2 deletions docker/start
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ run_graph_node() {
wait_for_ipfs "$ipfs"
sleep 5
graph-node \
--node-id "${node_id//-/_}" \
--node-id "$node_id" \
--config "$GRAPH_NODE_CONFIG" \
--ipfs "$ipfs"
else
Expand All @@ -70,7 +70,7 @@ run_graph_node() {
sleep 5

graph-node \
--node-id "${node_id//-/_}" \
--node-id "$node_id" \
--postgres-url "$postgres_url" \
--ethereum-rpc $ethereum \
--ipfs "$ipfs"
Expand All @@ -96,6 +96,14 @@ start_combined_node() {
run_graph_node
}

# Allow operators to opt out of legacy character
# restrictions on the node ID by setting enablement
# variable to a non-zero length string:
if [ -z "$GRAPH_NODE_ENABLE_NEW_BEHAVIOR" ]
then
node_id="${node_id//-/_}"
fi

if [ -n "$disable_core_dumps" ]
then
ulimit -c 0
Expand Down
10 changes: 2 additions & 8 deletions graph/src/data/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,8 @@ impl NodeId {
pub fn new(s: impl Into<String>) -> Result<Self, ()> {
let s = s.into();

// Enforce length limit
if s.len() > 63 {
return Err(());
}

// Check that the ID contains only allowed characters.
// Note: these restrictions are relied upon to prevent SQL injection
if !s.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') {
// Enforce minimum and maximum length limit
if s.len() > 63 || s.len() < 1 {
return Err(());
}

Expand Down
2 changes: 1 addition & 1 deletion node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async fn main() {
}

let node_id =
NodeId::new(opt.node_id.clone()).expect("Node ID must contain only a-z, A-Z, 0-9, and '_'");
NodeId::new(opt.node_id.clone()).expect("Node ID must be between 1 and 63 characters in length");
let query_only = config.query_only(&node_id);

// Obtain subgraph related command-line arguments
Expand Down

0 comments on commit cf256e2

Please sign in to comment.