Skip to content

fix: restore the contact list by fixing dav template module interop - #794

Merged
oc-tmueller merged 3 commits into
masterfrom
fix/dav-template-esm-interop
Sep 22, 2026
Merged

oc-tmueller merged 3 commits into
masterfrom
fix/dav-template-esm-interop

Conversation

@oc-tmueller

Copy link
Copy Markdown
Contributor

The bug

On ownCloud 11 the Contacts app loads its shell — "New contact", "All contacts",
"Settings" — and then shows nothing. No address book, no contacts. Every call into
the vendored dav library's request templates throws, eight times per page load:

TypeError: template.propfind is not a function
    at propfind3 (…/apps/contacts/js/dav/dav.js:5150:32)

js/dav/lib/template/index.js was CommonJS re-exporting six modules that are each ESM
with a single export default:

exports.propfind = require('./propfind');

Under the original babel 5 pipeline a lone default export was collapsed onto
module.exports, so that yielded the function. esbuild — which built the bundle
currently on master — follows the spec: require() of an ESM module yields the
namespace object. template.propfind became { default: fn }, and every
template.X(...) call site in lib/request.js threw.

All six templates were affected — propfind, addressBookQuery, calendarQuery,
syncCollection, mkcol, proppatch — which between them cover listing, searching,
sync, creating an address book and renaming one. Effectively the whole app.

Introduced by #775, which migrated the bundled xmldom to @xmldom/xmldom (a real
security fix) and regenerated the bundle with a new bundler.

The fix

The barrel re-exports the default bindings explicitly, which is correct under any
bundler and does not rely on babel 5's semantics. Six lines.

Why the rest of the diff exists

js/dav/dav.js could not be rebuilt from this repository at all. Reproducing it needed
three things the repo did not contain:

  • shims/xmlhttprequest.js — a one-line browser shim for the node-only
    xmlhttprequest package. The committed bundle embeds it from
    ../../../shims/xmlhttprequest.js, a path outside the repository.
  • a locked dependency tree — runtime deps are compiled into the bundle, so the
    ^0.8.13 range on @xmldom/xmldom made the artifact float. url must stay at
    0.11.0: it is imported by accounts.js, calendars.js, client.js and
    contacts.js, and 0.11.1+ swap querystring for qs, pulling in ~45 further modules.
  • the esbuild invocation — recorded nowhere. fix(deps): migrate vendored dav lib from xmldom to @xmldom/xmldom #775 switched bundlers but left the
    Makefile describing the babel 5 + browserify pipeline it had replaced. That gap is
    what let the bundle drift from its sources undetected.

So: the shim is committed, direct versions are exact, package-lock.json is committed
(un-ignored by name), and the Makefile's dav.js target runs esbuild via npm ci. Two
consecutive runs now produce a byte-identical bundle.

A dav bundle CI job rebuilds the bundle and fails if it differs from what is committed
— the check that would have caught this. It deletes the bundle before rebuilding so it
cannot pass by having make decide nothing was stale, and compares with
git status --porcelain because git diff reports neither untracked nor deleted paths.

make in js/dav was also broken independently of this: its default goal runs
uglify-js 2.x, whose ES5-only parser cannot read esbuild output at all
(Unexpected token: punc ()) on line 1). It now minifies with esbuild, and dav.js —
the only artifact this repo consumes — is the default goal. make clean no longer
deletes dav.js, which is tracked.

Rebuilding moves the bundled @xmldom/xmldom from 0.8.13 to 0.8.15; called out in the
changelog.

Verification

Against owncloud/server:11.0.0 with the app installed and signed:

before after
address books rendered 0 1
contact list nodes 1 34
ng-view content 372 bytes 22 512 bytes
console exceptions 8 0
address book controls — Rename, Link, Download, Delete, Import

The contact detail form is populated from the vCard (phone, email, structured name), and
occ integrity:check-app contacts passes on a tarball signed with the new G2 certificate
— then correctly reports INVALID_HASH and exits 1 when a signed file is tampered with.

I also confirmed the same esbuild recipe against the unfixed source still
reproduces the fault, so the repair is the source change and not the rebuild.

js/tests/dav_bundle.js guards all six templates. Verified as a real gate, not a
passing test: against the broken bundle seven of the eight cases fail with the
production error; against the fixed bundle all pass (21 tests total, karma/Firefox).

Note

dav bundle is not in the contacts-status-checks ruleset, so it reports but cannot
block a merge until owncloud/admin adds it. Given the whole premise here is that CI
stayed green while the app was unusable, that is worth doing.

@oc-tmueller
oc-tmueller requested a review from a team as a code owner September 22, 2026 21:13
The Contacts app loaded but showed no address books and no contacts on
ownCloud 11. Every call into the vendored dav library's request templates
threw "template.propfind is not a function", eight times per page load.

js/dav/lib/template/index.js was CommonJS re-exporting six modules that
are each ESM with a single `export default`:

    exports.propfind = require('./propfind');

Under the original babel 5 pipeline a lone default export was collapsed
onto module.exports, so that yielded the function. esbuild - which built
the bundle currently committed - follows the spec instead: require() of
an ESM module yields the namespace object. So template.propfind became
{ default: fn } and every template.X(...) call site in lib/request.js
threw. All six templates were affected: propfind, addressBookQuery,
calendarQuery, syncCollection, mkcol and proppatch, which between them
cover listing, searching, sync, creating an address book and renaming
one - effectively the whole app.

The barrel now re-exports the default bindings explicitly, which is
correct under any bundler and does not depend on babel 5's semantics.

Also make js/dav/dav.js reproducible, because it was not. Rebuilding it
needed three things the repository did not contain:

- shims/xmlhttprequest.js, a one-line browser shim for the node-only
  xmlhttprequest package. The committed bundle embeds it from
  ../../../shims/xmlhttprequest.js - a path outside the repository.
- a locked dependency tree. Runtime dependencies are compiled into the
  bundle, so the ^0.8.13 range on @xmldom/xmldom silently made the
  artifact float; `url` additionally has to stay at 0.11.0, since 0.11.1+
  swap querystring for qs and pull in ~45 further modules. Direct
  versions are now exact and package-lock.json is committed, un-ignored
  by name in .gitignore.
- the esbuild invocation itself, which was recorded nowhere. 0d133ae
  (#775) switched bundlers but left the Makefile describing the babel 5 +
  browserify pipeline it had replaced, which is how the bundle came to
  drift from its sources undetected.

The Makefile's dav.js target now runs esbuild, `npm ci` builds from the
lockfile, and two consecutive runs produce a byte-identical bundle. Its
dav.min.js target also worked only by accident before: uglify-js 2.x has
an ES5-only parser and cannot read esbuild output at all, so `make` in
js/dav failed on its default goal. It now minifies with esbuild, and
dav.js - the only artifact this repository consumes - is the default
goal.

Rebuilding moves the bundled @xmldom/xmldom from 0.8.13 to 0.8.15, which
accounts for most of the diff in dav.js; it is called out in the
changelog.

Verified against owncloud/server:11.0.0 with the app installed: before,
the address book list is empty and the console carries eight "not a
function" exceptions; after, the address book and its contacts render,
the contact detail form is populated from the vCard, the Rename / Link /
Download / Delete / Import controls appear, and the console is clean.
Confirmed the same esbuild recipe against the unfixed source still
reproduces the fault, so the repair is the source change and not the
rebuild.

Signed-off-by: Thomas Müller <[email protected]>
js/dav/dav.js is a generated artifact that karma already loads, but
nothing asserted anything about it, so the interop break in the previous
commit passed CI green: the whole app was unusable while every test
passed.

Adds a spec that builds a propfind, addressBookQuery and syncCollection
request and checks the rendered propfind body. Verified as a real gate by
running it against the broken bundle, where four of the five cases fail
with the production error - "TypeError: template.propfind is not a
function" - and against the fixed bundle, where all pass.

Signed-off-by: Thomas Müller <[email protected]>
Follow-up to the previous two commits, from reviewing them.

- .github/workflows/main.yml: a `dav bundle` job rebuilds js/dav/dav.js
  and fails if it differs from the committed bundle. The previous commits
  supply a correct Makefile and a lockfile but no gate, so an edit under
  js/dav/lib with no rebuild would ship a stale bundle exactly as before.
  Since the build is byte-reproducible from the lockfile, comparing
  against the worktree is reliable. Two details matter: the bundle is
  deleted before the rebuild, so the job cannot pass by having `make`
  decide nothing was out of date - which is what would happen the moment
  node_modules gets cached - and the comparison uses
  `git status --porcelain`, since `git diff` reports neither untracked
  nor deleted paths and so would call a PR that dropped dav.js from the
  index "in sync". Verified all three ways: green in sync, red on an
  edited template, red on a bundle removed from the index.

- js/dav/Makefile: `npm ci` instead of `npm install`, with
  package-lock.json as a prerequisite. Without it, bumping a dependency
  in the lockfile alone left make thinking dav.js was up to date and the
  superseded dependency stayed compiled in. `clean` no longer deletes
  dav.js, which is tracked - it used to remove the bundle the app loads
  and leave the worktree broken. The minify target uses --sourcemap
  rather than --sourcemap=external: the latter omits the
  sourceMappingURL comment, which would orphan the map where the uglify
  invocation it replaces emitted the link.

- js/dav/package.json: drop browserify. Nothing has referenced it since
  the bundler switch, and it was the largest contributor to the
  lockfile - removing it takes the lock from 236K to 181K and drops a
  duplicate punycode. babel stays: test/mocha.opts still uses
  babel/register.

- js/dav/package-lock.json: regenerated clean. The first version carried
  an extraneous punycode 1.4.1 that `npm install` would delete, so the
  committed lockfile was not the tree npm considered canonical and a
  build dirtied the worktree. `npm install` is now idempotent against it.

- js/dav/.gitignore: ignore dav.min.js.map, the map's new name.

- js/tests/dav_bundle.js: cover the other three templates - mkcol and
  proppatch, which back creating and renaming an address book, and
  calendarQuery. All six now fail against the broken bundle and pass
  against the fixed one.

The only change to dav.js is two module-path comments: with the
extraneous entry gone, url's punycode 1.3.2 hoists to the top level
instead of staying nested. The bundled version is unchanged.

Note that `dav bundle` is not yet in the contacts-status-checks ruleset,
so it reports but cannot block a merge until owncloud/admin adds it.

Signed-off-by: Thomas Müller <[email protected]>
@oc-tmueller
oc-tmueller force-pushed the fix/dav-template-esm-interop branch from 8a5c0a0 to 671f1e2 Compare September 22, 2026 21:24
@oc-tmueller
oc-tmueller merged commit e529582 into master Sep 22, 2026
12 checks passed
@oc-tmueller
oc-tmueller deleted the fix/dav-template-esm-interop branch September 22, 2026 21:37
oc-tmueller added a commit that referenced this pull request Sep 22, 2026
Cuts 1.6.0, the first release since 1.5.5 (2018-12-11).

- CHANGELOG.md: [Unreleased] closed out as [1.6.0], link refs updated
- sonar-project.properties: sonar.projectVersion 1.0 -> 1.6.0
- package.json: version 1.5.4 -> 1.6.0, two releases behind

appinfo/info.xml needs no change - it already declares 1.6.0, bumped in
5c9b81e along with the min-version/max-version 11 dependency and the
PHP 8.3 requirement, but never tagged. The release workflow added by
#793 enforces that the tag matches <version>.

Dropping ownCloud 10 and PHP < 8.3 gets its own Removed section rather
than a bullet in the middle of Changed: it is the one fact in this
changelog that can leave an administrator with a disabled app after an
upgrade, so it should not be easy to skim past. For the same reason #775
is under Security rather than Fixed - it replaces a bundled XML parser
carrying unpatched advisories, and reads as a rename otherwise.

The #794 entry says explicitly that the regression it fixes never
reached a release. 1.5.5 predates #775 by eight years, so without that
note an administrator reading these release notes would conclude their
current install has a broken contact list and treat 1.6.0 as urgent.

The dependency line names the development toolchain explicitly: every
package.json change since 1.5.5 was a devDependency. The one bundled
runtime library that does move is @xmldom/xmldom, via #794, and that is
called out on its own line.

Signed-off-by: Thomas Müller <[email protected]>
oc-tmueller added a commit that referenced this pull request Sep 23, 2026
Cuts 1.6.0, the first release since 1.5.5 (2018-12-11).

- CHANGELOG.md: [Unreleased] closed out as [1.6.0], link refs updated
- sonar-project.properties: sonar.projectVersion 1.0 -> 1.6.0
- package.json: version 1.5.4 -> 1.6.0, two releases behind

appinfo/info.xml needs no change - it already declares 1.6.0, bumped in
5c9b81e along with the min-version/max-version 11 dependency and the
PHP 8.3 requirement, but never tagged. The release workflow added by
#793 enforces that the tag matches <version>.

Dropping ownCloud 10 and PHP < 8.3 gets its own Removed section rather
than a bullet in the middle of Changed: it is the one fact in this
changelog that can leave an administrator with a disabled app after an
upgrade, so it should not be easy to skim past. For the same reason #775
is under Security rather than Fixed - it replaces a bundled XML parser
carrying unpatched advisories, and reads as a rename otherwise.

The #794 entry says explicitly that the regression it fixes never
reached a release. 1.5.5 predates #775 by eight years, so without that
note an administrator reading these release notes would conclude their
current install has a broken contact list and treat 1.6.0 as urgent.

The dependency line names the development toolchain explicitly: every
package.json change since 1.5.5 was a devDependency. The one bundled
runtime library that does move is @xmldom/xmldom, via #794, and that is
called out on its own line.

Signed-off-by: Thomas Müller <[email protected]>
Co-authored-by: Thomas Müller <[email protected]>
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