-
Notifications
You must be signed in to change notification settings - Fork 9
Add Selenium regression test for list audit detail #3048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
labkey-bpatel
wants to merge
1
commit into
release25.7-SNAPSHOT
Choose a base branch
from
25.7_fb_owasp_lists_audit
base: release25.7-SNAPSHOT
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,11 +24,15 @@ | |||||||||||||||||||||||
| import org.junit.Test; | ||||||||||||||||||||||||
| import org.junit.experimental.categories.Category; | ||||||||||||||||||||||||
| import org.labkey.remoteapi.CommandException; | ||||||||||||||||||||||||
| import org.labkey.remoteapi.Connection; | ||||||||||||||||||||||||
| import org.labkey.remoteapi.domain.Domain; | ||||||||||||||||||||||||
| import org.labkey.remoteapi.domain.DomainResponse; | ||||||||||||||||||||||||
| import org.labkey.remoteapi.domain.PropertyDescriptor; | ||||||||||||||||||||||||
| import org.labkey.remoteapi.domain.SaveDomainCommand; | ||||||||||||||||||||||||
| import org.labkey.remoteapi.query.Filter; | ||||||||||||||||||||||||
| import org.labkey.remoteapi.query.SelectRowsCommand; | ||||||||||||||||||||||||
| import org.labkey.remoteapi.query.SelectRowsResponse; | ||||||||||||||||||||||||
| import org.labkey.remoteapi.query.Sort; | ||||||||||||||||||||||||
| import org.labkey.serverapi.reader.TabLoader; | ||||||||||||||||||||||||
| import org.labkey.test.BaseWebDriverTest; | ||||||||||||||||||||||||
| import org.labkey.test.Locator; | ||||||||||||||||||||||||
|
|
@@ -857,6 +861,92 @@ public void testCustomViews() | |||||||||||||||||||||||
| crossContainerLookupTest(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * CWE-639 (IDOR): a list audit event loaded by user-controlled rowId in | ||||||||||||||||||||||||
| * ListItemDetailsAction must be tied back to the URL-requested listId before its | ||||||||||||||||||||||||
| * old/new record maps are rendered. Without this, listId=X&rowId=N-belonging-to-Y | ||||||||||||||||||||||||
| * would render List Y's audit payload inside List X's details page. | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * Builds two lists in the same container, generates a modify-audit-event on the | ||||||||||||||||||||||||
| * second one, then verifies the action refuses to render it when the URL names the | ||||||||||||||||||||||||
| * first list. A positive control confirms the matched-listId path still works, so | ||||||||||||||||||||||||
| * the test fails if the predicate is ever inverted/over-rejects. | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||
| public void testAuditDetailRejectsRowIdFromOtherList() throws Exception | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| final String LIST_X = "IDOR_VICTIM_LIST"; // attacker claims to be viewing details for this list | ||||||||||||||||||||||||
| final String LIST_Y = "IDOR_SOURCE_LIST"; // audit event actually belongs to this list | ||||||||||||||||||||||||
| final String NAME_FIELD = "Name"; | ||||||||||||||||||||||||
| final String LIST_Y_ROW_VALUE = "y-original"; | ||||||||||||||||||||||||
| final String LIST_Y_ROW_EDITED = "y-modified-secret"; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| log("Set up two lists in the same container, each with a Name field"); | ||||||||||||||||||||||||
| _listHelper.createList(getProjectName(), LIST_X, "Key", | ||||||||||||||||||||||||
| new FieldDefinition(NAME_FIELD, ColumnType.String)); | ||||||||||||||||||||||||
| _listHelper.createList(getProjectName(), LIST_Y, "Key", | ||||||||||||||||||||||||
| new FieldDefinition(NAME_FIELD, ColumnType.String)); | ||||||||||||||||||||||||
|
Comment on lines
+885
to
+888
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the ListHelper to create the lists adds a bunch of unnecessary UI interaction. The API helper will speed this up a ton.
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| log("Insert and then modify a row in List Y so it generates an audit event with old/new record maps"); | ||||||||||||||||||||||||
| _listHelper.goToList(LIST_Y); | ||||||||||||||||||||||||
| _listHelper.clickImportData() | ||||||||||||||||||||||||
| .setText(NAME_FIELD + "\n" + LIST_Y_ROW_VALUE) | ||||||||||||||||||||||||
| .submit(); | ||||||||||||||||||||||||
| DataRegionTable yTable = new DataRegionTable("query", getDriver()); | ||||||||||||||||||||||||
| yTable.clickEditRow(yTable.getRowIndex(LIST_Y_ROW_VALUE)); | ||||||||||||||||||||||||
| setFormElement(Locator.name("quf_" + NAME_FIELD), LIST_Y_ROW_EDITED); | ||||||||||||||||||||||||
| clickButton("Submit"); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| log("Discover List X's listId and the audit rowId for List Y's modification event"); | ||||||||||||||||||||||||
| Connection cn = createDefaultConnection(); | ||||||||||||||||||||||||
| int listXId = lookupListId(cn, LIST_X); | ||||||||||||||||||||||||
| int listYId = lookupListId(cn, LIST_Y); | ||||||||||||||||||||||||
| int listYAuditRowId = lookupListAuditRowId(cn, LIST_Y); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| log("Attack: URL says listId=" + LIST_X + " but rowId points at the audit event for " + LIST_Y); | ||||||||||||||||||||||||
| String attackUrl = WebTestHelper.buildURL("list", getProjectName(), "listItemDetails", | ||||||||||||||||||||||||
| Map.of("listId", String.valueOf(listXId), "rowId", String.valueOf(listYAuditRowId))); | ||||||||||||||||||||||||
| beginAt(attackUrl); | ||||||||||||||||||||||||
| assertEquals("Action should render normally (200), not throw", 200, getResponseCode()); | ||||||||||||||||||||||||
| assertTextPresent("No details available for this event"); | ||||||||||||||||||||||||
| assertTextNotPresent(LIST_Y_ROW_VALUE); // proof of non-disclosure: pre-edit value | ||||||||||||||||||||||||
| assertTextNotPresent(LIST_Y_ROW_EDITED); // proof of non-disclosure: post-edit value | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| log("Positive control: same rowId but with the matching listId must still render the audit changes"); | ||||||||||||||||||||||||
| String matchedUrl = WebTestHelper.buildURL("list", getProjectName(), "listItemDetails", | ||||||||||||||||||||||||
| Map.of("listId", String.valueOf(listYId), "rowId", String.valueOf(listYAuditRowId))); | ||||||||||||||||||||||||
| beginAt(matchedUrl); | ||||||||||||||||||||||||
| assertEquals(200, getResponseCode()); | ||||||||||||||||||||||||
| assertTextPresent(LIST_Y_ROW_VALUE); | ||||||||||||||||||||||||
| assertTextPresent(LIST_Y_ROW_EDITED); | ||||||||||||||||||||||||
| assertTextNotPresent("No details available for this event"); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| private int lookupListId(Connection cn, String listName) throws Exception | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| SelectRowsCommand cmd = new SelectRowsCommand("exp", "Lists"); | ||||||||||||||||||||||||
| cmd.setColumns(List.of("RowId", "Name")); | ||||||||||||||||||||||||
| cmd.addFilter(new Filter("Name", listName, Filter.Operator.EQUAL)); | ||||||||||||||||||||||||
| SelectRowsResponse rs = cmd.execute(cn, getProjectName()); | ||||||||||||||||||||||||
| if (rs.getRows().isEmpty()) | ||||||||||||||||||||||||
| throw new AssertionError("No exp.Lists row for " + listName); | ||||||||||||||||||||||||
| return ((Number) rs.getRows().get(0).get("RowId")).intValue(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| private int lookupListAuditRowId(Connection cn, String listName) throws Exception | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| // Most-recent ListAuditEvent for this list; the row-modify above will be it. | ||||||||||||||||||||||||
| SelectRowsCommand cmd = new SelectRowsCommand("auditLog", "ListAuditEvent"); | ||||||||||||||||||||||||
| cmd.setColumns(List.of("RowId", "ListName", "Comment")); | ||||||||||||||||||||||||
| cmd.addFilter(new Filter("ListName", listName, Filter.Operator.EQUAL)); | ||||||||||||||||||||||||
| cmd.setSorts(List.of(new Sort("RowId", Sort.Direction.DESCENDING))); | ||||||||||||||||||||||||
| cmd.setMaxRows(1); | ||||||||||||||||||||||||
| SelectRowsResponse rs = cmd.execute(cn, getProjectName()); | ||||||||||||||||||||||||
| if (rs.getRows().isEmpty()) | ||||||||||||||||||||||||
| throw new AssertionError("No ListAuditEvent for " + listName); | ||||||||||||||||||||||||
| return ((Number) rs.getRows().get(0).get("RowId")).intValue(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /* Issue 23487: add regression coverage for batch insert into list with multiple errors | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This comment could just be a reference to the kanban issue.