Skip to content

Commit 7bd95a9

Browse files
committed
Scope laboratory assay template lookups to the request container
The assay_run_templates lookups in DefaultAssayParser.saveTemplate, DefaultAssayParser.getTemplateRowMap, and AssayHelper.saveTemplate filtered only by rowid, which is the table's global primary key. Because Table.update also operates by global PK, a user could pass a templateId belonging to another container and have that foreign template loaded and updated (runid/status), bypassing container authorization. Each lookup now adds a container condition scoped to the request container before reading or updating the row. Follow-up to #286.
1 parent 5a5bd07 commit 7bd95a9

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

laboratory/api-src/org/labkey/api/laboratory/assay/DefaultAssayParser.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,11 @@ protected void saveTemplate(ViewContext ctx, int templateId, int runId) throws B
466466
{
467467
try
468468
{
469-
//validate the template exists
469+
//validate the template exists in this container
470470
TableInfo ti = DbSchema.get("laboratory").getTable("assay_run_templates");
471-
TableSelector ts = new TableSelector(ti, new SimpleFilter(FieldKey.fromString("rowid"), templateId), null);
471+
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("rowid"), templateId);
472+
filter.addCondition(FieldKey.fromString("container"), _container);
473+
TableSelector ts = new TableSelector(ti, filter, null);
472474
if (ts.getRowCount() == 0)
473475
{
474476
throw new BatchValidationException(Collections.singletonList(new ValidationException("Unknown template: " + templateId)), null);
@@ -586,7 +588,9 @@ protected Map<String, Map<String, Object>> getTemplateRowMap(ImportContext conte
586588

587589
TableInfo ti = DbSchema.get("laboratory").getTable("assay_run_templates");
588590

589-
TableSelector ts = new TableSelector(ti, new SimpleFilter(FieldKey.fromString("rowid"), templateId), null);
591+
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("rowid"), templateId);
592+
filter.addCondition(FieldKey.fromString("container"), _container);
593+
TableSelector ts = new TableSelector(ti, filter, null);
590594
Map<String, Object>[] maps = ts.getMapArray();
591595
if (maps.length == 0)
592596
{

laboratory/src/org/labkey/laboratory/assay/AssayHelper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.labkey.api.data.Container;
3434
import org.labkey.api.data.ContainerManager;
3535
import org.labkey.api.data.RuntimeSQLException;
36+
import org.labkey.api.data.SimpleFilter;
3637
import org.labkey.api.data.TSVMapWriter;
3738
import org.labkey.api.data.Table;
3839
import org.labkey.api.data.TableInfo;
@@ -51,6 +52,7 @@
5152
import org.labkey.api.laboratory.assay.AssayDataProvider;
5253
import org.labkey.api.laboratory.assay.AssayImportMethod;
5354
import org.labkey.api.query.BatchValidationException;
55+
import org.labkey.api.query.FieldKey;
5456
import org.labkey.api.query.ValidationException;
5557
import org.labkey.api.security.User;
5658
import org.labkey.api.util.FileUtil;
@@ -139,6 +141,15 @@ public Map<String, Object> saveTemplate(User u, Container c, ExpProtocol protoco
139141
}
140142
else
141143
{
144+
// Table.update operates by global PK, so verify the existing template lives in this container before updating it
145+
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("rowid"), templateId);
146+
filter.addCondition(FieldKey.fromString("container"), c);
147+
if (!new TableSelector(ti, filter, null).exists())
148+
{
149+
errors.addRowError(new ValidationException("Unknown template: " + templateId));
150+
throw errors;
151+
}
152+
142153
row.put("rowid", templateId);
143154
row = Table.update(u, ti, row, templateId);
144155
}

0 commit comments

Comments
 (0)