Repository navigation
JSE-72: report ActiveX controls, embedded packages, customUI and unreferenced parts - #140
Merged
Merged
Conversation
…ferenced parts read now walks the whole relationship graph of the package after the sheets (scanPackageParts in src/internal/read/scan.ts) and reports, as UNSUPPORTED_PART, four new part kinds: activeX, embeddedPackage, customUI and unreferencedPart. oleObject, vbaProject, externalLink, connections and queryTable are also reported where they sit deeper in the graph (under a drawing or table) or on a sheet left out by the sheets option. Passive kinds keep their previous reporting. The scan reads only relationships parts, each once per read (Package caches them), without marking them consumed, within the zip and XML limits; it never inflates the parts it reports. A malformed nested relationships part is reported as unreferenced instead of failing the read. Office's [trash]/ folder is the only name-based exemption.
…backstop - Part names are compared in OPC canonical form on both sides (percent-escapes decoded as UTF-8 except %2F, %5C, %25; case-insensitive). resolveTarget treats only literal . and .. as dot segments, so %2E%2E, %2F, %5C and double encoding stay inside one name. Entries equivalent to an earlier entry are listed as unreferenced instead of being dropped. - xlMacrosheet and xlIntlMacrosheet relationships are macro sheets. - Relationship types compare case-insensitively. Content types of ActiveX, OLE objects, VBA, macro sheets, web add-ins and embedded Office documents classify a part whatever relationship reaches it. - New partKind 'webExtension' for Office web add-ins; attachedToolbars, VBA signatures and wordVbaData report as 'vbaProject'. - The [trash]/ exemption matches exactly; docs state it and that DTDs or over-deep XML in nested relationships parts now throw.
…ding - Equivalent zip entry names (equal after percent-decoding and case folding) are an invalid package: ZIP_INVALID. Package.shadowed is gone. - The [trash]/ exemption is removed; unreferencedPart and the new invalidPartName warnings list every name in a new `parts` field. - invalidPartName: zip entry names and relationship targets OPC forbids (%2F or %5C in a segment, percent-encoded dot segments, a trailing dot). Such a target is followed both as a decoder reads it (as 2.4.0 did) and literally, so content behind it is found either way. - canonicalPartName is one hand-written linear pass with no decoder calls, decodes once and is idempotent (a bare % becomes %25); entry keys are computed once. The Package constructor consults the signal for every entry. - Every Override/Default content type of a part is checked, so a later passive type cannot hide an active one. More content types: templates, add-ins, slides, application/vnd.ms-office.oleObject. - Docs and changeset list the behaviour changes against 2.4.0.
…nships, long names - A part reached as a relationship target is queued for its own relationships even if it was already accounted for, so a target naming a relationships part or [Content_Types].xml no longer hides what that part's relationships list. Such a target is invalidPartName. - Every .rels entry is read as its owner's relationships after the walk, also when nothing reaches the owner; what only it lists is classified but stays unreferenced. - A <Relationship> without Id or Target is kept out of the model as before, classified by the scan, and reported as invalidPartName. - Override PartNames: forbidden names are reported, and the content type applies under both readings. - Targets and PartNames longer than 3 x 65,535 characters are not canonicalised (they cannot name a part) and are reported. - A target with a malformed escape is read literally, as 2.4.0 did. - Format detection uses 2.4.0's override table (last wins).
…els names - contentType() (format decisions) uses 2.4.0's raw PartName table, so a forbidden Override such as /xl/x/../workbook.xml cannot change the format; the scan still checks both readings through contentTypes(). - Orphan relationships parts are recognised by canonical name, so %5Frels and .r%65ls spellings are classified too. - Docs and changeset: the length limit is taken before dot segments are resolved (a padded target is not followed); every relationships part, orphans included, is parsed, so a DTD in an orphan .rels now throws.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
read(andimportDataset, which passes read warnings on) now walks the whole relationship graph of the package after the sheets and reports more content it does not read asUNSUPPORTED_PART. Four newpartKindvalues:activeX: acontroloractiveXControlBinaryrelationship, or any relationship to a part whose content type isapplication/vnd.ms-office.activeX….embeddedPackage: apackagerelationship (for example a.docxunderxl/embeddings/).customUI: a…/relationships/ui/extensibilityrelationship (2006 and 2007 namespaces), i.e.customUI/customUI.xml/customUI14.xml.unreferencedPart: one warning for all parts no relationship reaches;partis the first in zip order, the message gives the count.The scan also reports
oleObject,vbaProject,externalLink,connectionsandqueryTablewhere the workbook's and read sheets' own relationships did not already report them: under a drawing, under a table (where Excel puts query tables), or on a sheet left out bysheets. Drawings, images, comments, tables, pivots and the other passive kinds are reported exactly as before, so an image inside a drawing still gives onlydrawing.Unreferenced parts:
[Content_Types].xml, the relationships part of a reached part, and Office's[trash]/folder are not reported. Nothing else is exempt by name (thumbnail, printer settings, calcChain and custom XML have their own relationships in a well-formed package; an orphaned copy is reported, since a name-based exemption would be the place to hide a payload). None of the corpus files (openpyxl, LibreOffice and import fixtures, and every non-heavy conformance-corpus file this library writes) has an unreferenced part; a test pins that. A relationships part that is not well-formed XML is reported as unreferenced (with what only it would reach) instead of failing the read.The scan is
scanPackageParts(pkg)insrc/internal/read/scan.ts, returning every classified part (breadth first) and the unreferenced parts, so a futureinspect()can reuse it. It reads only relationships parts, once each (Package.relsnow caches them, and has apeekmode that does not mark them consumed, so the internalretainPartsstill keeps them), within the existing zip and XML limits, and never inflates the parts it classifies. It consults the signal per part and every 4,096 relationships.Existing warnings keep their shape and order; new warnings come after the sheets' warnings.
Why
Apps that store uploaded workbooks want to refuse files that carry ActiveX controls, embedded files, ribbon callbacks or payloads hidden in the zip. Before this, only workbook and read-sheet relationships were checked, and these kinds were not reported at all.
Tests
test/read/package-scan.test.ts(new, written first and seen failing): one test per new kind (ActiveX on a sheet, only under a drawing, by content type; embedded package on a sheet and under VML; customUI for both namespaces; unreferencedvbaProject.bin, several orphans with and without a content type, orphan subgraphs, malformed nested rels,[trash]and case/dot-segment targets), existing kinds found deeper, thesheetsoption,importDataset, limits (payload overmaxEntryBytesreported without being read, nested rels under the XML depth limit,retainParts, abort), thescanPackagePartsresult, and every corpus file staying without these warnings.docs/api.md(§5.2 package scan and unreferenced parts, yielding, §7.3ExcelPartKindand theUNSUPPORTED_PARTrow, §8 security table), package README, minor changeset.