This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new 134226ae99 RelationshipTransformService: keep an empty TargetMode in
the digest (#1511)
134226ae99 is described below
commit 134226ae99e3497640aa95f0e8dc7f041bba2012
Author: Nayyar <[email protected]>
AuthorDate: Mon Nov 2 18:24:03 2026 +0530
RelationshipTransformService: keep an empty TargetMode in the digest (#1511)
---
.../services/RelationshipTransformService.java | 6 ++++--
.../poi/poifs/crypt/dsig/TestSignatureInfo.java | 23 ++++++++++++++++++++++
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java
b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java
index 054c2c85b9..4133180690 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java
@@ -217,8 +217,10 @@ public class RelationshipTransformService extends
TransformService {
Element el = (Element)nl.item(i);
String id = el.getAttribute("Id");
if (sourceIds.contains(id)) {
- String targetMode = el.getAttribute("TargetMode");
- if (targetMode == null || targetMode.isEmpty()) {
+ // the default applies to an absent attribute only: the
package model reads a
+ // present TargetMode with any value other than "Internal" as
an external
+ // relationship, so an empty one has to be digested as what it
is
+ if (!el.hasAttribute("TargetMode")) {
el.setAttribute("TargetMode", "Internal");
}
rsList.add(el);
diff --git
a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java
b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java
index 0f8c26acb8..6ad61e434d 100644
---
a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java
+++
b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java
@@ -29,6 +29,7 @@ import static
org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
@@ -551,6 +552,28 @@ class TestSignatureInfo {
}
}
+ @Test
+ void testEmptyTargetModeOnSignedRelationship() throws Exception {
+ // an empty TargetMode is not the absent attribute: the package reads
it as an external
+ // relationship, so the signed styles part is no longer part of the
document
+ InputStream modified = rewriteSignedDocx(entries -> {
+ String rel = "Target=\"styles.xml\"/>";
+ byte[] rels = entries.get("word/_rels/document.xml.rels");
+ assertThat(new String(rels, StandardCharsets.UTF_8),
containsString(rel));
+ entries.put("word/_rels/document.xml.rels", replace(rels, rel,
"Target=\"styles.xml\" TargetMode=\"\"/>"));
+ });
+
+ try (OPCPackage pkg = OPCPackage.open(modified);
+ XWPFDocument doc = new XWPFDocument(pkg)) {
+ assertNull(doc.getStyles(), "the styles part is not reachable
through the relationship anymore");
+
+ SignatureInfo si = new SignatureInfo();
+ si.setOpcPackage(pkg);
+ si.setSignatureConfig(new SignatureConfig());
+ assertFalse(si.verifySignature(), "signature must not cover a
relationship whose target mode was changed");
+ }
+ }
+
/**
* Copies hello-world-signed.docx, adding {@code rel} to _rels/.rels and,
if {@code addTamperedPart}
* is set, a word/tampered.xml main part which says "Tampered" instead of
"Hello world"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]