Fetching - Always sort the key order of JSON content for less false alerts (May cause an alert on upgrade, but will be better going forwards) #1219

This commit is contained in:
dgtlmoon
2022-12-15 09:13:09 +01:00
committed by GitHub
parent e970fef991
commit b7a2501d64
2 changed files with 53 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
import hashlib
import json
import logging
import os
import re
@@ -167,6 +168,14 @@ class perform_site_check():
include_filters_rule.append("json:$")
has_filter_rule = True
if is_json:
# Sort the JSON so we dont get false alerts when the content is just re-ordered
try:
fetcher.content = json.dumps(json.loads(fetcher.content), sort_keys=True)
except Exception as e:
# Might have just been a snippet, or otherwise bad JSON, continue
pass
if has_filter_rule:
json_filter_prefixes = ['json:', 'jq:']
for filter in include_filters_rule:
@@ -174,6 +183,8 @@ class perform_site_check():
stripped_text_from_html += html_tools.extract_json_as_string(content=fetcher.content, json_filter=filter)
is_html = False
if is_html or is_source:
# CSS Filter, extract the HTML that matches and feed that into the existing inscriptis::get_text