diff --git a/helpers/sri_helper.py b/helpers/sri_helper.py index 9d04b1ff..f98cbd8d 100644 --- a/helpers/sri_helper.py +++ b/helpers/sri_helper.py @@ -2,7 +2,8 @@ import re import urllib import urllib.parse -from helpers.data_helper import append_domain_entry +from helpers.data_helper import append_domain_entry,\ + append_domain_entry_with_key, has_domain_entry from helpers.setting_helper import get_config from models import Rating @@ -61,12 +62,26 @@ def rate_sri(result_dict, global_translation, local_translation, rating += sub_rating elif 'HTML-FOUND' in result_dict[domain]['features'] and\ (domain in (org_domain, org_www_domain)): + rating = Rating(global_translation, get_config('general.review.improve-only')) rating.set_overall(1.0) - rating.set_standards(1.0, - local_translation('TEXT_REVIEW_SRI_NONE_COMPLIANT').format(domain)) - rating.set_integrity_and_security(1.0, - local_translation('TEXT_REVIEW_SRI_NONE_COMPLIANT').format(domain)) + + if get_config('general.review.details') and \ + has_domain_entry(domain, 'sri-findings', 'sri-candidates', result_dict): + candidates_str_list = '' + candidates = result_dict[domain]['sri-findings']['sri-candidates'] + for candidate in candidates: + candidates_str_list += f" - '{candidate}'\r\n" + + rating.set_integrity_and_security(1.0, + local_translation( + 'TEXT_REVIEW_SRI_NONE_COMPLIANT_DETAILS' + ).format(domain)) + rating.integrity_and_security_review = rating.integrity_and_security_review +\ + candidates_str_list + else: + rating.set_integrity_and_security(1.0, + local_translation('TEXT_REVIEW_SRI_NONE_COMPLIANT').format(domain)) return rating @@ -131,12 +146,28 @@ def append_sri_data_for_html(req_domain, res, result): 'features', 'SRI-WITH-ERRORS', result) + for sri_error in sri_errors: + append_domain_entry_with_key( + req_domain, + 'sri-findings', + 'sri-errors', + sri_error, + result) + elif len(candidates) == 0: append_domain_entry( req_domain, 'features', 'SRI-COMPLIANT', result) + else: + for candidate in candidates: + append_domain_entry_with_key( + req_domain, + 'sri-findings', + 'sri-candidates', + candidate['raw'], + result) def get_sris(req_domain, content): """ @@ -324,7 +355,7 @@ def get_sri_candidates(req_domain, content): if name in ('link'): if link_rel in ('stylesheet', 'preload', 'modulepreload'): should_have_integrity = True - elif name in ('script') and candidate['src'] is not None: + elif name in ('script') and ('src' in candidate and candidate['src'] is not None): should_have_integrity = True # NOTE: Remove same domain resources diff --git a/locales/en/LC_MESSAGES/http_validator.mo b/locales/en/LC_MESSAGES/http_validator.mo index 8c1ca6b5..d4215bef 100644 Binary files a/locales/en/LC_MESSAGES/http_validator.mo and b/locales/en/LC_MESSAGES/http_validator.mo differ diff --git a/locales/en/LC_MESSAGES/http_validator.po b/locales/en/LC_MESSAGES/http_validator.po index f83e46b7..2835f3ca 100644 --- a/locales/en/LC_MESSAGES/http_validator.po +++ b/locales/en/LC_MESSAGES/http_validator.po @@ -196,7 +196,10 @@ msgid "TEXT_REVIEW_SRI_COMPLIANT" msgstr "- {0}, Subresource Integrity (SRI)" msgid "TEXT_REVIEW_SRI_NONE_COMPLIANT" -msgstr "- {0}, Needs Subresource Integrity (SRI)" +msgstr "- {0}, Subresource Integrity (SRI) is required" + +msgid "TEXT_REVIEW_SRI_NONE_COMPLIANT_DETAILS" +msgstr "- {0}, Subresource Integrity (SRI) is required for following entries" msgid "TEXT_REVIEW_SRI_WITH_ERRORS" -msgstr "- {0}, Incorrectly using Subresource Integrity (SRI)" +msgstr "- {0}, Subresource Integrity (SRI) is used incorrectly" diff --git a/locales/gov/LC_MESSAGES/http_validator.mo b/locales/gov/LC_MESSAGES/http_validator.mo index 8c1ca6b5..d983dae1 100644 Binary files a/locales/gov/LC_MESSAGES/http_validator.mo and b/locales/gov/LC_MESSAGES/http_validator.mo differ diff --git a/locales/gov/LC_MESSAGES/http_validator.po b/locales/gov/LC_MESSAGES/http_validator.po index f83e46b7..2835f3ca 100644 --- a/locales/gov/LC_MESSAGES/http_validator.po +++ b/locales/gov/LC_MESSAGES/http_validator.po @@ -196,7 +196,10 @@ msgid "TEXT_REVIEW_SRI_COMPLIANT" msgstr "- {0}, Subresource Integrity (SRI)" msgid "TEXT_REVIEW_SRI_NONE_COMPLIANT" -msgstr "- {0}, Needs Subresource Integrity (SRI)" +msgstr "- {0}, Subresource Integrity (SRI) is required" + +msgid "TEXT_REVIEW_SRI_NONE_COMPLIANT_DETAILS" +msgstr "- {0}, Subresource Integrity (SRI) is required for following entries" msgid "TEXT_REVIEW_SRI_WITH_ERRORS" -msgstr "- {0}, Incorrectly using Subresource Integrity (SRI)" +msgstr "- {0}, Subresource Integrity (SRI) is used incorrectly" diff --git a/locales/sv/LC_MESSAGES/http_validator.po b/locales/sv/LC_MESSAGES/http_validator.po index 966100e0..880c59d6 100644 --- a/locales/sv/LC_MESSAGES/http_validator.po +++ b/locales/sv/LC_MESSAGES/http_validator.po @@ -196,7 +196,10 @@ msgid "TEXT_REVIEW_SRI_COMPLIANT" msgstr "- {0}, Subresource Integrity (SRI)" msgid "TEXT_REVIEW_SRI_NONE_COMPLIANT" -msgstr "- {0}, Kräver Subresource Integrity (SRI)" +msgstr "- {0}, Subresource Integrity (SRI) krävs" + +msgid "TEXT_REVIEW_SRI_NONE_COMPLIANT_DETAILS" +msgstr "- {0}, Subresource Integrity (SRI) krävs för följande HTML-element" msgid "TEXT_REVIEW_SRI_WITH_ERRORS" -msgstr "- {0}, Använder Subresource Integrity (SRI) på felaktigt sätt" +msgstr "- {0}, Subresource Integrity (SRI) används på felaktigt sätt"