Skip to content

Commit

Permalink
Merge branch 'main' into update-version-in-package-json
Browse files Browse the repository at this point in the history
  • Loading branch information
7h3Rabbit authored Oct 16, 2024
2 parents 3f63d75 + 2ae120c commit 424a4d6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions helpers/csp_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ def append_csp_data(req_url, req_domain, res, org_domain, result):
bool: True if there is a match in the CSP findings, False otherwise.
"""
csp_findings_match = False
# TODO: Remove text empty check when sitespeed has fixed https://github.com/sitespeedio/sitespeed.io/issues/4295
if 'content' in res and 'text' in res['content'] and res['content']['text'] != '':
if 'mimeType' in res['content'] and 'text/html' in res['content']['mimeType']:
csp_findings_match = csp_findings_match or append_csp_data_for_html(
Expand Down
51 changes: 38 additions & 13 deletions helpers/sri_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def rate_sri(result_dict, global_translation, local_translation,
'TEXT_REVIEW_SRI_WITH_ERRORS_DETAILS'
).format(domain))

rating.standards_review = rating.standards_review +\
sub_rating.standards_review = sub_rating.standards_review +\
errors_str_list
else:
sub_rating.set_standards(3.0,
Expand All @@ -77,8 +77,8 @@ def rate_sri(result_dict, global_translation, local_translation,
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)
sub_rating = Rating(global_translation, get_config('general.review.improve-only'))
sub_rating.set_overall(1.0)

if get_config('general.review.details') and \
has_domain_entry(domain, 'sri-findings', 'sri-candidates', result_dict):
Expand All @@ -87,15 +87,22 @@ def rate_sri(result_dict, global_translation, local_translation,
for candidate in candidates:
candidates_str_list += f" - `{candidate}`\r\n"

rating.set_integrity_and_security(1.0,
sub_rating.set_standards(1.0,
local_translation(
'TEXT_REVIEW_SRI_NONE_COMPLIANT'
).format(domain))
sub_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 +\
sub_rating.integrity_and_security_review = sub_rating.integrity_and_security_review +\
candidates_str_list
else:
rating.set_integrity_and_security(1.0,
sub_rating.set_standards(1.0,
local_translation('TEXT_REVIEW_SRI_NONE_COMPLIANT').format(domain))
sub_rating.set_integrity_and_security(1.0,
local_translation('TEXT_REVIEW_SRI_NONE_COMPLIANT').format(domain))
rating += sub_rating

return rating

Expand All @@ -111,7 +118,9 @@ def append_sri_data(req_domain, res, result):
res (dict): The response dictionary containing the content.
result (dict): The result dictionary where the CSP data will be appended.
"""
if 'content' in res and 'text' in res['content']:

# TODO: Remove text empty check when sitespeed has fixed https://github.com/sitespeedio/sitespeed.io/issues/4295
if 'content' in res and 'text' in res['content'] and res['content']['text'] != '':
if 'mimeType' in res['content'] and 'text/html' in res['content']['mimeType']:
append_sri_data_for_html(
req_domain,
Expand Down Expand Up @@ -154,7 +163,13 @@ def append_sri_data_for_html(req_domain, res, result):
if found_candidate is not None:
candidates.remove(found_candidate)

is_sri_compliant = not has_domain_entry(req_domain,
'features',
'SRI-NONE-COMPLIANT',
result)

if len(sri_errors) > 0:
is_sri_compliant = False
append_domain_entry(
req_domain,
'features',
Expand All @@ -167,14 +182,10 @@ def append_sri_data_for_html(req_domain, res, result):
'sri-errors',
sri_error,
result)

elif len(candidates) == 0:
append_domain_entry(
req_domain,
'features',
'SRI-COMPLIANT',
result)
is_sri_compliant = is_sri_compliant and True
else:
is_sri_compliant = False
for candidate in candidates:
append_domain_entry_with_key(
req_domain,
Expand All @@ -183,6 +194,20 @@ def append_sri_data_for_html(req_domain, res, result):
candidate['raw'],
result)

if is_sri_compliant:
append_domain_entry(
req_domain,
'features',
'SRI-COMPLIANT',
result)
else:
append_domain_entry(
req_domain,
'features',
'SRI-NONE-COMPLIANT',
result)


def get_sris(req_domain, content):
"""
Extracts Subresource Integrity (SRI) information from HTML content.
Expand Down

0 comments on commit 424a4d6

Please sign in to comment.