Skip to content

ZCU-PUB/Fix dspace-customers 1083 V4: bind vocabulary node id as an XPath variable - #1768

Draft
jr-rk wants to merge 1 commit into
customer/zcu-pubfrom
zcu-pub/be-vocabulary-xpath-variable
Draft

jr-rk wants to merge 1 commit into
customer/zcu-pubfrom
zcu-pub/be-vocabulary-xpath-variable

Conversation

@jr-rk

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

Copy link
Copy Markdown

References

Port of dtq-dev PR 1556 (commit 612aa63). dspace-customers issue 1083, finding V4.
Upstream commits ceab952 (DSpace#11075, 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

  • getMatches and getBestMatch bind the search text, and getChoice, getChoicesByParent and getParentChoice bind the node id as XPath variables.
  • New test testNodeIdIsNotEvaluatedAsXPath. The test farm.xml gets a pond node under s40.
  • The diff is the same as dtq-dev PR 1556. The cherry-pick had no conflicts.
  • Tests: DSpaceControlledVocabularyTest. Locally on this branch (7.6.1): Tests run: 2, 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

…Path variable

Port of dtq-dev PR 1556 (commit 612aa63).
@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

Search-text bindings lack regression tests for apostrophes, injection-shaped input, and multi-level variable mapping, while the XPath resolver unnecessarily repeats lowercasing for each candidate node.

2 open issues
What changed in this PR

This PR hardens controlled-vocabulary lookups against XPath injection by binding search text and node IDs as variables rather than inserting them into expressions.

Changes:

  • Adds variable binding for search, exact-match, and node-ID lookups.
  • Adds regression tests for injection-shaped node IDs and valid hierarchy navigation.
  • Extends the test vocabulary with a nested pond node.
File Description
dspace-api/​src/​test/​java/​org/​dspace/​content/​authority/​DSpaceControlledVocabularyTest.java Adds node-ID regression coverage and strengthens the search assertion.
dspace-api/​src/​test/​data/​dspaceFolder/​config/​controlled-vocabularies/​farm.xml Adds pond beneath s40 for hierarchy tests.
dspace-api/​src/​main/​java/​org/​dspace/​content/​authority/​DSpaceControlledVocabulary.java Binds XPath variables and includes minor code and Javadoc cleanup.

Review effort: Balanced

String varName = variableName.getLocalPart();
if (varName.startsWith("var")) {
int index = Integer.parseInt(varName.substring(3));
return textHierarchy[index].toLowerCase();
Comment on lines +205 to +209
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.

2 participants