From ca34c7fb1db22405f927b326ee73eedbc88da66b Mon Sep 17 00:00:00 2001 From: Stephen Tomkinson Date: Fri, 6 Dec 2024 16:24:15 +0000 Subject: [PATCH] Attempt to improve OU tree handling of symbols in names with special meanings, such as slash and comma --- .../event_tracker/bloodhoundserver_outree.html | 6 +++--- event_tracker/views_bloodhound.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/event_tracker/templates/event_tracker/bloodhoundserver_outree.html b/event_tracker/templates/event_tracker/bloodhoundserver_outree.html index 33e40ac..804cc17 100644 --- a/event_tracker/templates/event_tracker/bloodhoundserver_outree.html +++ b/event_tracker/templates/event_tracker/bloodhoundserver_outree.html @@ -48,7 +48,7 @@ 'data' : { 'url' : "{% url "event_tracker:bloodhound-ou-api" %}", 'data' : function (node) { - return { 'id' : node.id }; + return { 'id' : decodeURIComponent(node.id) }; } }, 'themes': { @@ -97,9 +97,9 @@ }).on('changed.jstree', function (e, data) { var i, j, r = []; for(i = 0, j = data.selected.length; i < j; i++) { - r.push(data.instance.get_node(data.selected[i]).text); + r.push(decodeURIComponent(data.instance.get_node(data.selected[i]).text)); } - $('#selected').attr("src", "{% url "event_tracker:bloodhound-node" "dndndn" %}".replace("dndndn", data.node.id.split(",").reverse().join(","))); + $('#selected').attr("src", "{% url "event_tracker:bloodhound-node" "dndndn" %}".replace("dndndn", encodeURIComponent(decodeURIComponent(data.node.id.split(",").reverse().join(","))))); }); }); diff --git a/event_tracker/views_bloodhound.py b/event_tracker/views_bloodhound.py index ce2657e..3b3136c 100644 --- a/event_tracker/views_bloodhound.py +++ b/event_tracker/views_bloodhound.py @@ -114,12 +114,12 @@ def _get_dn_children(tx, parent): parent = [] children = tx.run(""" - match (n) where reverse(split(n.distinguishedname, ','))[$parent_len] is not null and - reverse(split(n.distinguishedname, ','))[0..$parent_len] = $parent - return distinct reverse(split(n.distinguishedname, ','))[$parent_len] as nodetext, - reverse(split(n.distinguishedname, ','))[0..$node_len] as nodepath, + match (n) where reverse(split(replace(n.distinguishedname, "\\\\,", "%5c%2c"), ','))[$parent_len] is not null and + reverse(split(replace(n.distinguishedname, "\\\\,", "%5c%2c"), ','))[0..$parent_len] = $parent + return distinct reverse(split(replace(n.distinguishedname, "\\\\,", ","), ','))[$parent_len] as nodetext, + reverse(split(replace(n.distinguishedname, "\\\\,", "%5c%2c"), ','))[0..$node_len] as nodepath, count(*) as childcount, - not max(size(split(n.distinguishedname, ',')) > $node_len) as isleaf, + not max(size(split(replace(n.distinguishedname, "\\\\,", "%5c%2c"), ',')) > $node_len) as isleaf, collect(distinct labels(n)) as labs, true in collect(n.owned) as owned order by left(nodetext, 3) <> "DC=", isleaf, toLower(split(nodetext, '=')[-1])""", parent=parent, parent_len=len(parent), node_len=len(parent) + 1)