miaow2 / netbox-config-diff

Find diff and push rendered device configurations from NetBox to devices and apply them.
https://miaow2.github.io/netbox-config-diff/
Apache License 2.0
74 stars 4 forks source link

Diff doesn't render if there are unescaped characters in the config #70

Closed notscottsmith closed 1 month ago

notscottsmith commented 2 months ago

NetBox version v3.7.8

Describe the bug If the config which is rendered into the JS var jsonDiff has unescaped characters, the django filter "safe" doesn't pick them up.

Fix Changing it to escapejs seems to fix it for me but I've not done extensive testing.

miaow2 commented 2 months ago

Hi @notscottsmith, please, provide an example of the diff, that does not render

notscottsmith commented 2 months ago

Here's an excerpt of the config which would likely be causing an issue:

-radius-server template UFAAS-RADIUS-TEMPLATE
-radius-server shared-key cipher %^%#bK5vCFIF:Y0Uk1,2"fh"<W!dLL#fDP`XNl@F84E>[EZx5UoC&S+<:zT*&kKYe&5i'c0:.L-O-=&3q.zU\NV\<7L*m=7Ewl~ue7/M%^%#
-radius-server authentication 172.16.20.16 1812 source ip-address 192.168.172.254 weight 80
-radius-server authentication 172.16.30.6 1812 source ip-address 192.168.172.254 weight 40
-radius-server accounting 172.16.20.16 1813 source ip-address 192.168.172.254 weight 80
-radius-server accounting 172.16.30.6 1813 source ip-address 192.168.172.254 weight 40
-radius-server retransmit 4 timeout 8
-radius-server dead-time 1
-radius-attribute nas-ip 192.168.172.254
-radius-server algorithm loading-share

The cipher that gets created in the config has backticks in it as well as other characters which aren't being escaped by using "safe".

e.g. focusing on the cipher line: radius-server shared-key cipher %^%#bK5vCFIF:Y0Uk1,2"fh"<W!dLL#fDP`XNl@F84E>[EZx5UoC&S+<:zT*&kKYe&5i'c0:.L-O-

That's how the text looks when it's using "safe", which will cause problems straight away.

Whereas when using escapejs, the same line looks like this: radius\u002Dserver shared\u002Dkey cipher %^%#bK5vCFIF:Y0Uk1,2\u0022fh\u0022\u003CW!dLL#fDP\u0060XNl@F84E\u003E[EZx5UoC\u0026S+\u003C:zT*\u0026kKYe\u00265i\u0027c0:.L\u002DO\u002D\u003D\u00263q.zU\u005CNV\u005C\u003C7L*m\u003D7Ewl~ue7/M%^%#

Which allows it to be rendered in JS without problems.