Skip to content

Commit c456b51

Browse files
committed
Suppress confirmed false-positive static-analysis findings
SonarCloud's PR quality gate surfaced the whole dev-vs-main diff as new code, flagging 38 findings that are false positives for this library: file I/O on developer-supplied report/config/action-JSON paths (S8707/S2083), intentional plain HTTP on localhost/dev-configured or test-fixture endpoints (S5332), non-cryptographic randomness in chaos injection and matrix sampling (S2245), test-fixture credentials (S2068), exact numeric passthrough assertions (S1244), and the valid Py3.12+ tarfile extractall(filter=data) kwarg already guarded for older interpreters (S930). Each line gets a NOSONAR comment with a justification, matching the existing convention. No logic changed; unit suite passes (4302) under Selenium 4.41 and 4.45.
1 parent 525c284 commit c456b51

21 files changed

Lines changed: 38 additions & 38 deletions

File tree

je_web_runner/utils/action_formatter/formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,5 @@ def format_file(path: str | Path, write: bool = True,
141141
formatted = format_text(original, indent=indent)
142142
changed = formatted != original
143143
if write and changed:
144-
target.write_text(formatted, encoding="utf-8")
144+
target.write_text(formatted, encoding="utf-8") # NOSONAR S2083 — developer-supplied path (own action-JSON file), not untrusted input
145145
return formatted, changed

je_web_runner/utils/chaos_hooks/chaos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def plan_chaos(
102102
skipped.append(index)
103103
continue
104104
# S2245 ok: deterministic seeded scheduling for tests; not cryptographic.
105-
if rng.random() >= fault_rate:
105+
if rng.random() >= fault_rate: # NOSONAR S2245 — non-crypto use (chaos/sampling), not security-sensitive
106106
continue
107-
fault = rng.choice(list(faults))
107+
fault = rng.choice(list(faults)) # NOSONAR S2245 — non-crypto use (chaos/sampling), not security-sensitive
108108
events.append(ChaosEvent(step_index=index, step_name=name, fault=fault))
109109
if max_events is not None and len(events) >= max_events:
110110
break

je_web_runner/utils/driver_pin/pinner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def _safe_extract_tar(archive: tarfile.TarFile, target_dir: Path) -> None:
201201
# 3.9.17 / 3.10.12 / 3.11.4) which rejects escaping links; fall back to a
202202
# plain extract on older interpreters that lack the parameter.
203203
try:
204-
archive.extractall(target_dir, filter="data") # nosec B202 — members validated + data filter
204+
archive.extractall(target_dir, filter="data") # nosec B202 — members validated + data filter # NOSONAR S930 — valid tarfile 'filter' kwarg (Py3.12+), guarded by except TypeError
205205
except TypeError:
206206
archive.extractall(target_dir) # nosec B202 — members validated above
207207

je_web_runner/utils/flag_matrix/matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def build_matrix( # NOSONAR S3776 — cohesive logic; planned refactor in follo
129129
keep_count = max(0, sample_size - len(pinned_combos))
130130
# S2245 ok: deterministic seeded sampling for reproducible test combos;
131131
# not used for any cryptographic / security decision.
132-
filtered = rng.sample(filtered, keep_count)
132+
filtered = rng.sample(filtered, keep_count) # NOSONAR S2245 — non-crypto use (chaos/sampling), not security-sensitive
133133
sampled = True
134134
else:
135135
sampled = False

je_web_runner/utils/generate_report/generate_html_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def generate_html_report(html_name: str = "default_name"):
173173
new_html_string = generate_html()
174174
try:
175175
# ``_lock`` serialises concurrent writers; ``with`` guarantees release.
176-
with _lock, open(html_name + ".html", "w", encoding="utf-8") as file_to_write:
176+
with _lock, open(html_name + ".html", "w", encoding="utf-8") as file_to_write: # NOSONAR S8707 — developer-supplied path (own report/config file), not untrusted input
177177
file_to_write.write(new_html_string)
178178
except OSError as error:
179179
web_runner_logger.error(f"generate_html_report write failed: {error!r}")

je_web_runner/utils/generate_report/generate_json_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ def generate_json_report(json_file_name: str = "default_name"):
8585
# 輸出成功紀錄
8686
# Write success records
8787
try:
88-
with _lock, open(json_file_name + "_success.json", "w", encoding="utf-8") as file_to_write:
88+
with _lock, open(json_file_name + "_success.json", "w", encoding="utf-8") as file_to_write: # NOSONAR S8707 — developer-supplied path (own report/config file), not untrusted input
8989
json.dump(dict(success_dict), file_to_write, indent=4)
9090
except (OSError, TypeError, ValueError) as error:
9191
web_runner_logger.error(f"generate_json_report, json_file_name: {json_file_name}, failed: {error!r}")
9292

9393
# 輸出失敗紀錄
9494
# Write failure records
9595
try:
96-
with _lock, open(json_file_name + "_failure.json", "w", encoding="utf-8") as file_to_write:
96+
with _lock, open(json_file_name + "_failure.json", "w", encoding="utf-8") as file_to_write: # NOSONAR S8707 — developer-supplied path (own report/config file), not untrusted input
9797
json.dump(dict(failure_dict), file_to_write, indent=4)
9898
except (OSError, TypeError, ValueError) as error:
9999
web_runner_logger.error(f"generate_json_report, json_file_name: {json_file_name}, failed: {error!r}")

je_web_runner/utils/generate_report/generate_junit_xml_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def generate_junit_xml_report(junit_file_name: str = "default_name") -> None:
9393
junit_xml = generate_junit_xml()
9494
target = junit_file_name + "_junit.xml"
9595
try:
96-
with _lock, open(target, "w", encoding="utf-8") as file_to_write:
96+
with _lock, open(target, "w", encoding="utf-8") as file_to_write: # NOSONAR S8707 — developer-supplied path (own report/config file), not untrusted input
9797
file_to_write.write('<?xml version="1.0" encoding="UTF-8"?>\n')
9898
file_to_write.write(junit_xml)
9999
except OSError as error:

je_web_runner/utils/generate_report/generate_xml_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ def generate_xml_report(xml_file_name: str = "default_name"):
5959
# 輸出失敗報告
6060
# Write failure report
6161
try:
62-
with _lock, open(xml_file_name + "_failure.xml", "w", encoding="utf-8") as file_to_write:
62+
with _lock, open(xml_file_name + "_failure.xml", "w", encoding="utf-8") as file_to_write: # NOSONAR S8707 — developer-supplied path (own report/config file), not untrusted input
6363
file_to_write.write(failure_xml)
6464
except OSError as error:
6565
web_runner_logger.error(f"generate_xml_report, xml_file_name: {xml_file_name}, failed: {error!r}")
6666

6767
# 輸出成功報告
6868
# Write success report
6969
try:
70-
with _lock, open(xml_file_name + "_success.xml", "w", encoding="utf-8") as file_to_write:
70+
with _lock, open(xml_file_name + "_success.xml", "w", encoding="utf-8") as file_to_write: # NOSONAR S8707 — developer-supplied path (own report/config file), not untrusted input
7171
file_to_write.write(success_xml)
7272
except OSError as error:
7373
web_runner_logger.error(f"generate_xml_report, xml_file_name: {xml_file_name}, failed: {error!r}")

je_web_runner/utils/json/json_file/json_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def read_action_json(json_file_path: str) -> list:
2323
# 檔案不存在或不是檔案
2424
# File does not exist or is not a file
2525
raise WebRunnerJsonException(cant_find_json_error)
26-
with lock, open(json_file_path, encoding="utf-8") as read_file:
26+
with lock, open(json_file_path, encoding="utf-8") as read_file: # NOSONAR S8707 — developer-supplied path (own report/config file), not untrusted input
2727
return json.load(read_file)
2828

2929

je_web_runner/utils/linter/migration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ def migrate_action_file(path: str, dry_run: bool = True) -> dict[str, Any]:
8080
raise MigrationError(f"action file not found: {path}")
8181
web_runner_logger.info(f"migrate_action_file: {path} dry_run={dry_run}")
8282
try:
83-
with open(file_path, encoding="utf-8") as action_file:
83+
with open(file_path, encoding="utf-8") as action_file: # NOSONAR S8707 — developer-supplied path (own report/config file), not untrusted input
8484
data = json.load(action_file)
8585
except ValueError as error:
8686
raise MigrationError(f"action file not valid JSON: {path}") from error
8787
new_data, changes = migrate_action(data)
8888
written = False
8989
if changes and not dry_run:
90-
with open(file_path, "w", encoding="utf-8") as action_file:
90+
with open(file_path, "w", encoding="utf-8") as action_file: # NOSONAR S8707 — developer-supplied path (own report/config file), not untrusted input
9191
json.dump(new_data, action_file, indent=2, ensure_ascii=False)
9292
written = True
9393
return {"path": str(file_path), "changes": changes, "written": written}

0 commit comments

Comments
 (0)