naruto-lgtm opened a new pull request, #1579:
URL: https://github.com/apache/poi/pull/1579

   Repro: load an .xlsx that has an external hyperlink, call 
`setAddress("https://example.org/new";)` on it and save. `getAddress()` returns 
the new value until the file is reloaded, but the saved sheet still points to 
the original URL. A hyperlink removed with `Cell.removeHyperlink()` / 
`XSSFSheet.removeHyperlink()` is gone from the sheet XML, but its URL stays in 
`sheetN.xml.rels`.
   Cause: a loaded `XSSFHyperlink` holds the `PackageRelationship` it was read 
with, and `generateRelationIfNeeded` skips any link that already has one, so 
`setAddress` only changes `_location` and the old `r:id` and target are written 
back out. `XSSFSheet.write` regenerates `<hyperlinks>` from the in-memory list 
but never removes hyperlink relationships. That breaks code that rewrites or 
neutralises link targets in workbooks it did not create (link sanitising, URL 
rewriting, redacting tokens in URLs). The edit looks applied through the API, 
but the file that goes out still has the original target (CWE-212 for the 
removed-link case).
   Fix: when the address of a loaded hyperlink changes, `setAddress` drops its 
relationship (and the `location` fragment, which was part of the old address), 
so a new relationship is created on write. `XSSFSheet.write` then removes 
hyperlink relationships that no hyperlink refers to. That also covers removed 
links and the relationship left over when an unsaved link's address changes 
between two `write` calls. A link whose address is unchanged keeps its 
relationship, and copies split off a shared hyperlink keep sharing theirs. 
Other relationship types are not touched. 
`TestXSSFHyperlink.testChangeOrRemoveLoadedHyperlink` fails on trunk 
(`expected: <https://example.org/new> but was: 
<https://example.com/old#section>`) and passes with the change; `./gradlew 
:poi-ooxml:check` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to