From ddd5d2d8d2830b6233acfebc9a5d84292cf19d6f Mon Sep 17 00:00:00 2001 From: Pjotr Date: Fri, 9 Oct 2026 05:59:08 +0000 Subject: api: check dataset is public before serving sample data sampledata.get_sampledata and lmdb_sample_data.get_sample_data read LMDB directly by dataset/trait name with no check that the dataset is public and non-confidential. Add dataset_is_public() to db_utils, checked against ProbeSetFreeze/PublishFreeze/GenoFreeze, and use it in both handlers to return 404 before touching LMDB when the dataset isn't found or isn't public. Co-Authored-By: Claude Sonnet 5 --- gn3/api/lmdb_sample_data.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gn3/api/lmdb_sample_data.py') diff --git a/gn3/api/lmdb_sample_data.py b/gn3/api/lmdb_sample_data.py index eaa71c2..0f08488 100644 --- a/gn3/api/lmdb_sample_data.py +++ b/gn3/api/lmdb_sample_data.py @@ -5,6 +5,8 @@ from pathlib import Path import lmdb from flask import Blueprint, current_app, jsonify +from gn3.db_utils import database_connection, dataset_is_public + lmdb_sample_data = Blueprint("lmdb_sample_data", __name__) @@ -19,6 +21,9 @@ def get_sample_data(dataset: str, trait_id: int): Returns: JSON object mapping sample IDs to their values """ + with database_connection(current_app.config["SQL_URI"]) as conn, conn.cursor() as cursor: + if not dataset_is_public(cursor, dataset): + return jsonify(error="Dataset not found or not public"), 404 checksum = hashlib.md5( f"{dataset}-{trait_id}".encode() ).hexdigest() -- cgit 1.4.1