Skip to content

JSE-72: report ActiveX controls, embedded packages, customUI and unreferenced parts - #140

Merged
securedeveloper merged 6 commits into
mainfrom
jse-72
Dec 2, 2026
Merged

securedeveloper merged 6 commits into
mainfrom
jse-72

Conversation

@securedeveloper

Copy link
Copy Markdown
Owner

What

read (and importDataset, 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 as UNSUPPORTED_PART. Four new partKind values:

  • activeX: a control or activeXControlBinary relationship, or any relationship to a part whose content type is application/vnd.ms-office.activeX….
  • embeddedPackage: a package relationship (for example a .docx under xl/embeddings/).
  • customUI: a …/relationships/ui/extensibility relationship (2006 and 2007 namespaces), i.e. customUI/customUI.xml / customUI14.xml.
  • unreferencedPart: one warning for all parts no relationship reaches; part is the first in zip order, the message gives the count.

The scan also reports oleObject, vbaProject, externalLink, connections and queryTable where 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 by sheets. Drawings, images, comments, tables, pivots and the other passive kinds are reported exactly as before, so an image inside a drawing still gives only drawing.

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) in src/internal/read/scan.ts, returning every classified part (breadth first) and the unreferenced parts, so a future inspect() can reuse it. It reads only relationships parts, once each (Package.rels now caches them, and has a peek mode that does not mark them consumed, so the internal retainParts still 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; unreferenced vbaProject.bin, several orphans with and without a content type, orphan subgraphs, malformed nested rels, [trash] and case/dot-segment targets), existing kinds found deeper, the sheets option, importDataset, limits (payload over maxEntryBytes reported without being read, nested rels under the XML depth limit, retainParts, abort), the scanPackageParts result, and every corpus file staying without these warnings.
  • Docs: docs/api.md (§5.2 package scan and unreferenced parts, yielding, §7.3 ExcelPartKind and the UNSUPPORTED_PART row, §8 security table), package README, minor changeset.

…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.
@securedeveloper
securedeveloper merged commit bd26dda into main Dec 2, 2026
9 checks passed
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.

1 participant