Skip to content

Security fixes for ontology app#1514

Open
davmlaw wants to merge 1 commit intomasterfrom
security/ontology-fixes
Open

Security fixes for ontology app#1514
davmlaw wants to merge 1 commit intomasterfrom
security/ontology-fixes

Conversation

@davmlaw
Copy link
Copy Markdown
Contributor

@davmlaw davmlaw commented Apr 2, 2026

Summary

Applies security hardening to the ontology app identified in SACGF/variantgrid_private#3824. All findings require an authenticated session — no unauthenticated exploit paths exist.

  • H1 (panel_app_ontology.py): URL-encode gene_symbol in the PanelApp OntologyBuilder cache key
  • H2 (views_rest.py): Validate gene_symbol format with regex before serving/caching GeneDiseaseRelationshipView
  • H3 (views_rest.py): Remove dead urllib.parse.quote call whose result was never assigned; requests.get params encode automatically
  • M2 (models/models_ontology.py): get_from_slug now raises Http404 instead of letting DoesNotExist propagate as a 500
  • M3 (views_autocomplete.py): Validate forwarded ontology_service param against the OntologyService enum
  • M4 (views.py): Catch ValueError from OntologyService() constructor in ontology_term_text and raise Http404
  • M5 (models/models_ontology.py): Narrow bare except Exception: to except ValueError: in get_or_stub
  • M6 (models/models_ontology.py): Reject inputs over 200 chars in OntologyIdNormalized.normalize

Test plan

  • Visit an ontology term page (MONDO, OMIM, HPO, HGNC gene) — confirm normal display
  • Hit /ontology/term/<valid_term>/gene-list/ — confirm 200
  • Hit /ontology/term/INVALID_SLUG/gene-list/ — confirm 404 (not 500)
  • Hit the gene-disease-relationship endpoint with a valid gene symbol — confirm 200
  • Hit the gene-disease-relationship endpoint with ? or / in the gene symbol — confirm 404
  • Use the ontology autocomplete with a valid forwarded ontology_service — confirm filtered results
  • Use the ontology autocomplete with an invalid forwarded ontology_service — confirm no crash
  • Hit ontology_term_text URL with invalid service name — confirm 404 (not 500)

H1: Encode gene_symbol in PanelApp OntologyBuilder cache key (panel_app_ontology.py)
H2: Validate gene_symbol format before cached GeneDiseaseRelationshipView response
H3: Remove dead urllib.parse.quote call whose result was never assigned (views_rest.py)
M2: get_from_slug raises Http404 instead of unhandled DoesNotExist -> 500
M3: Validate forwarded ontology_service against OntologyService enum in autocomplete
M4: Catch ValueError from OntologyService() in ontology_term_text -> 404
M5: Narrow bare except Exception to except ValueError in get_or_stub
M6: Reject inputs >200 chars in OntologyIdNormalized.normalize
@davmlaw davmlaw force-pushed the security/ontology-fixes branch from 2133861 to 6bf46fd Compare April 2, 2026 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant