Skip to content

MENDELU/Fix dspace-customers 1083 V4: bind vocabulary node id as an XPath variable - #1770

Draft
jr-rk wants to merge 5 commits into
customer/mendelufrom
mendelu/be-vocabulary-xpath-variable
Draft

jr-rk wants to merge 5 commits into
customer/mendelufrom
mendelu/be-vocabulary-xpath-variable

Conversation

@jr-rk

@jr-rk jr-rk commented Nov 26, 2026

Copy link
Copy Markdown

References

Port of dtq-dev-93 PR 1650 (commit f08abc4). dspace-customers issue 1083, finding V4.
Upstream commits from DSpace#11078 (DSpace#11075 ported to dspace-9_x, label search) and aa419b9 (DSpace#11964, node id).
Upstream: DSpace#13386 (dspace-9_x) and DSpace#13387 (dspace-8_x) port the same node id fix (open).

Description

DSpaceControlledVocabulary put the node id and the search text from the request straight into XPath expressions, so a ' could change the query. Both are now XPath variables.

Instructions for Reviewers

9.1 does not have the label search fix yet (DSpace#11075, in 9.2 and later), and the dtq-dev-93 commit builds on it. So this PR has two parts:

  • The four commits of [Port dspace-9_x] Avoid injection vulnerability in controlled vocabulary lookup DSpace/DSpace#11078, cherry-picked with -x and their original authors. getMatches and getBestMatch bind the search text as XPath variables. They applied without conflicts.
  • The port of dtq-dev-93 PR 1650: getChoice, getChoicesByParent and getParentChoice evaluate //node[@id = $nodeId], the unused getNodeFromXPath is removed, and there is a new test testNodeIdIsNotEvaluatedAsXPath with a pond node under s40 in the test farm.xml. The diff is the same as PR 1650 and the cherry-pick had no conflicts.
  • Tests: DSpaceControlledVocabularyTest. Locally on this branch (9.1): Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Checkstyle passes.

Checklist

  • My PR is created against the branch it ports to
  • My PR is small in size
  • My PR follows the code conventions and passes Checkstyle
  • My PR includes Javadoc for the new public methods
  • My PR passes all tests and includes new or updated tests
  • My PR includes details on how to test it
  • No new dependencies, no REST contract change, no new configuration

odaysec and others added 5 commits November 26, 2026 08:39
(cherry picked from commit e94f0a9)
(cherry picked from commit 73326f2)
(cherry picked from commit c781ba2)
(cherry picked from commit 072d13e)
Documentation cleanup.
Clean up many IDE warnings.

(cherry picked from commit 7deaf1c)
(cherry picked from commit 01c533a)
(cherry picked from commit dac4941)
(cherry picked from commit 068eb40)
…Path variable

Port of dtq-dev-93 PR 1650 (commit f08abc4). It needs the label
search fix from upstream DSpace PR 11078 (PR 11075 ported to
dspace-9_x), which is cherry-picked in the four commits before this one.
@jr-rk jr-rk self-assigned this Nov 26, 2026
@jr-rk
jr-rk requested a balanced review from Copilot November 26, 2026 09:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The search-text binding lacks regression coverage for apostrophe-containing and XPath-shaped inputs through getMatches and getBestMatch, including label- and ID-valued vocabularies and hierarchical searches.

1 open issue
What changed in this PR

This PR hardens controlled-vocabulary lookups against XPath injection by backporting search-text variable binding and applying it to node IDs.

Changes:

  • Binds search text and node IDs as XPath variables instead of interpolating request values.
  • Adds node-ID injection regression tests and a nested vocabulary fixture.
  • Strengthens existing match assertions and includes minor code and Javadoc cleanup.
File Description
dspace-api/​src/​test/​java/​org/​dspace/​content/​authority/​DSpaceControlledVocabularyTest.java Tests literal node-ID handling and strengthens match assertions.
dspace-api/​src/​test/​data/​dspaceFolder/​config/​controlled-vocabularies/​farm.xml Adds a pond child for parent/child lookup tests.
dspace-api/​src/​main/​java/​org/​dspace/​content/​authority/​DSpaceControlledVocabulary.java Uses XPath variables for search text and node-ID lookups.

Review effort: Balanced

Comment on lines +224 to +228
xpath.setXPathVariableResolver(variableName -> {
String varName = variableName.getLocalPart();
if (varName.startsWith("var")) {
int index = Integer.parseInt(varName.substring(3));
return textHierarchy[index];

This branch has not been deployed

No deployments
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.

4 participants