fix: Made build output reproducible#3709
Open
Gueupo wants to merge 1 commit intomozilla:masterfrom
Open
Conversation
Fixes mozilla#3613. Replaced the unmaintained zip-dir dependency with an inline JSZip routine that walks the source tree in lexicographic order, stamps every entry (including explicit folder entries) with a fixed timestamp, normalizes path separators to '/', and pins platform: 'UNIX' in generateAsync so the same source produces identical bytes regardless of host OS. The default timestamp is 1980-01-01T00:00:00Z (the ZIP DOS-time minimum, obviously synthetic). It can be overridden via the standard SOURCE_DATE_EPOCH environment variable. Co-authored-by: kylekatarnls <kylekatarnls@gmail.com>
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.
Fixes #3613.
Motivation
web-ext buildcurrently produces ZIPs whose bytes vary between runs even whenthe source tree is unchanged: the
zip-dirwrapper passes nodateoption toJSZip, so every entry is stamped with
new Date(), and because of asynchronicity,order isn't guaranteed. This breaks downstream verification : checksum-based
provenance, SLSA/in-toto attestations, self-hosted XPI mirrors, build caches.
Per @Rob--W's design notes in #3613, this PR cuts out the
zip-dirmiddleman(unmaintained for 6 years) and uses JSZip directly with deterministic options.
What changed
src/cmd/build.js: replacedzip-dirwith an inline routine that walksthe source tree depth-first in lexicographic order, stamps every entry
(including explicit folder entries) with a fixed timestamp, normalizes
path separators to
/, and pinsplatform: 'UNIX'ingenerateAsync.1980-01-01T00:00:00Z(the ZIP DOS-time minimum,obviously synthetic). It can be overridden via the standard
SOURCE_DATE_EPOCHenvironment variable.package.json/package-lock.json: droppedzip-dir.jszipis alreadya direct dep (used by
submit-addon.js); no new dependencies.tests/unit/test-cmd/test.build.js: two new tests open the produced ZIPand assert every entry's date matches the expected fixed timestamp
(default +
SOURCE_DATE_EPOCHoverride). Verified that both tests failreliably on the pre-fix implementation.
README.md: updated.Non-obvious choices
SOURCE_DATE_EPOCHrather than aWEB_EXT_*variable: the canonicalspec name is what cargo, dpkg, sphinx and other reproducible-build tools
already read, so reusing it lets web-ext slot into existing pipelines.
1980-01-01as the default: it is the earliest timestamp the ZIP DOS-timeformat can encode, and the value being obviously synthetic signals to
anyone inspecting the archive that this is not a real mtime.
platform: 'UNIX': without it JSZip derives the external-attribute bytefrom
process.platform, which would make the same source producedifferent bytes on Windows vs Linux.
time by
git clone, which would defeat the cross-machine reproducibilitythe use case in Unpredictable checksum #3613 needs.
Acknowledgements
Big thanks to @kylekatarnls and @Rob--W for the original investigation and discussion !