Skip to content

fix: reject invalid manifest version segments in parcel-transformer-manifest - #1364

Open
akysil wants to merge 1 commit into
PlasmoHQ:mainfrom
akysil:fix/1362-isinvalidversion-in-parcel-transformer-m
Open

akysil wants to merge 1 commit into
PlasmoHQ:mainfrom
akysil:fix/1362-isinvalidversion-in-parcel-transformer-m

Conversation

@akysil

@akysil akysil commented Nov 28, 2026 •

Copy link
Copy Markdown

Details

This PR fixes isInvalidVersion in core/parcel-transformer-manifest/src/validate-version.ts, which could never return true (!isNaN(num) && num < 0 && num > 65536). As a result, validateSemanticVersion / validateBrowserVersion (used for version and minimum_chrome_version in the MV2/MV3 schemas) rejected only versions with too many segments, and the 0..65535 range in their error message was never checked.

Fixes #1362

Approach

  • A segment is now invalid unless it is a plain run of digits (/^\d+$/) no greater than 65535. The digit check is needed because Number() turns "", " 1", "1e3" and "0x10" into numbers, so fixing only the && / NaN logic would still let empty segments like 1..0 through.
  • The segment check runs before the segment-count check, so malformed input such as 1..3.4 reports the segment error. Inputs with valid segments but too many of them (4 for version, 5 for minimum_chrome_version) keep the existing ... to have at most N dots message.
  • Firefox loads extension versions that Chrome rejects (it warns and keeps the string). For firefox / gecko builds (PLASMO_BROWSER), the transformer validates with a copy of the schema whose version hook keeps the previous check (more than 3 segments fails, nothing else does), so Firefox builds behave exactly as before. The copy is picked on each transform; the shared schemas and both validators are not changed by it. minimum_chrome_version is checked strictly on every target.
input before (all targets) after: Chrome / other targets after: Firefox version
0, 1.2.3, 65535.65535.65535 valid valid valid
70000.0.0, 65536 valid ... must be dot-separated integers between 0 and 65535 valid (unchanged)
abc.def, 1.0.0-beta, 1.0.0+build, -1.0.0, 1..0, "", 1e3 valid ... must be dot-separated integers between 0 and 65535 valid (unchanged)
1..3.4 (version) at most 3 dots ... must be dot-separated integers between 0 and 65535 at most 3 dots (unchanged)
1.2.3.4 (version) at most 3 dots at most 3 dots at most 3 dots (unchanged)

The default version comes from package.json (manifest overrides can replace it). A Chrome build whose version has a prerelease suffix such as 1.0.0-beta now gets this error at build time instead of Chrome rejecting the manifest later.

To reproduce (Node 22.18+ runs the .ts file directly), from the repo root:

node -e 'import("./core/parcel-transformer-manifest/src/validate-version.ts").then((m) => { for (const v of ["1.2.3", "abc.def", "1.0.0-beta", "-1.0.0", "70000.0.0", "1..0", "1..3.4"]) console.log(JSON.stringify(v), "->", m.validateSemanticVersion(v), "|", m.validateBrowserVersion(v)) })'

On main every line except 1..3.4 prints undefined | undefined. With this change every line except 1.2.3 prints the must be dot-separated integers between 0 and 65535 error for both validators. This package has no test runner; I also checked the MV2 and MV3 schemas picked for no target, chrome, edge, firefox and gecko with an assertion script, including that both validators stay strict after a Firefox schema was picked.

Known limitations

  • Firefox/Gecko builds keep the previous version check: at most 3 segments, nothing else. Firefox itself accepts any version string with a warning; Firefox's recommended format and AMO's submission rules are not checked.
  • Chrome rules outside this issue are unchanged: leading-zero (01) and all-zero versions are still accepted, and four-segment extension versions are still rejected.
  • The upstream Node 20 PR workflow (workspace build plus examples build and test) was not run; it needs the git submodules initialized.

Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I agree to license this contribution under the MIT LICENSE
  • I checked the current PR for duplication.

Contacts

  • (OPTIONAL) Discord ID: b81234901824

If your PR is accepted, we will award you with the Contributor role on Discord server.

To join the server, visit: https://www.plasmo.com/s/d

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.

isInvalidVersion in parcel-transformer-manifest always returns false due to impossible boolean logic (&& instead of ||)

1 participant