File size: 1,544 Bytes
fa87992
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# fix_conn_map_xss.py
with open('frontend/js/app.js', 'r', encoding='utf-8') as f:
    content = f.read()

# Find the exact pattern using a simpler anchor
old = "onclick=\"EvidencePanel.open('${sanitize(e.connected_id||'')}','${sanitize(e.connected_to||'')}')\">"
new = "data-eid=\"${sanitize(e.connected_id||'')}\"\n             data-ename=\"${sanitize(e.connected_to||'')}\"\n             onclick=\"EvidencePanel.open(this.getAttribute('data-eid'),this.getAttribute('data-ename'))\">"

if old in content:
    content = content.replace(old, new)
    print('OK: connection map evidence onclick fixed with data-* attrs')
else:
    print('WARNING: trying alternate search...')
    # Try finding just a portion
    if "EvidencePanel.open('${sanitize(e.connected_id" in content:
        print('Found partial -- the exact quoting is different in your file')
        print('Showing context around EvidencePanel.open in connection map:')
        idx = content.find("EvidencePanel.open('${sanitize(e.connected_id")
        print(repr(content[idx-50:idx+150]))
    else:
        print('Pattern not found at all')

# Fix data-eid on Find Shortest Path button (unsanitized entityId)
old2 = 'data-eid="${entityId}"'
new2 = 'data-eid="${sanitize(entityId)}"'
if old2 in content:
    content = content.replace(old2, new2)
    print('OK: path-finder data-eid sanitized')
else:
    print('INFO: path-finder data-eid pattern not found (may already be sanitized)')

with open('frontend/js/app.js', 'w', encoding='utf-8') as f:
    f.write(content)
print('Done')