other
Error
- Location
- pharmgx_reporter.py:785
- Finding
- Missing or Unsupported Genetic Data Silently Produces Normal Phenotypes and Standard-Dose Recommendations## Vulnerability Details **File Location**: `pharmgx_reporter.py:785-910` **Vulnerability Type**: Fail-open medical inference and result-integrity failure **Risk Level**: High ### Vulnerable Code ```python def call_diplotype(gene, pgx_snps): gdef = GENE_DEFS[gene] if gdef.get("type") == "genotype": rsid = gdef["rsid"] if rsid in pgx_snps: return pgx_snps[rsid]["genotype"] return gdef["ref"] + gdef["ref"] detected = [] for rsid, vdef in gdef["variants"].items(): if rsid in pgx_snps: gt = pgx_snps[rsid]["genotype"] alt = vdef["alt"].upper() alt_count = gt.count(alt) if alt != "DEL" and alt != "INS" and alt != "TA7" else 0 if alt_count > 0: detected.append({"rsid": rsid, "allele": vdef["allele"], "copies": alt_count, "effect": vdef["effect"]}) if gdef.get("type") == "dpyd": if not detected: return "Normal/Normal" v = detected[0] if v["copies"] == 2: return f"{v['allele']}/{v['allele']}" return f"Normal/{v['allele']}" if not detected: return f"{gdef['ref']}/{gdef['ref']}" ``` ```python def call_phenotype(gene, diplotype): gdef = GENE_DEFS[gene] norm = diplotype.upper() for desc, conditions in gdef["phenotypes"].items(): for cond in conditions: if norm == cond.upper(): return desc parts = cond.split("/") if len(parts) == 2 and norm == f"{parts[1]}/{parts[0]}".upper(): return desc return "Normal (inferred)" ``` ```python def phenotype_to_key(phenotype_desc): """Map phenotype description to GUIDELINES rec key.""" mapping = { "Normal Metabolizer": "normal_metabolizer", "Intermediate Metabolizer": "intermediate_metabolizer", ...[truncated 3878 chars]
- Remediation
- ## Remediation Suggestions 1. Introduce explicit states such as `Unknown`, `Not tested`, `Insufficient coverage`, and `Unsupported diplotype`. 2. Track expected and observed SNP coverage independently for every gene. 3. Infer a reference allele only when the relevant loci have valid reference genotype calls; never infer it merely because a record is absent. 4. Return `Unknown` rather than `Normal (inferred)` when a diplotype is not present in the phenotype mapping. 5. Remove the default `normal_metabolizer` fallback from `phenotype_to_key()`. Return `None` or raise a controlled validation error for unknown values. 6. Do not generate medication recommendations for genes with insufficient coverage or unsupported phenotypes. 7. Replace the standard-dose fallback in `lookup_drugs()` with an explicit “No recommendation available” classification. 8. Add prominent per-gene coverage and confidence fields to the report. 9. Reject wholly unknown formats and files that do not meet a documented minimum coverage threshold. 10. Add negative tests for empty files, partial files, malformed genotype calls, unsupported diplotypes, and missing recommendation keys.
