codex-security icon indicating copy to clipboard operation
codex-security copied to clipboard

check-package.mjs rejects valid npm tarballs when Windows tar emits CRLF

Open ShawnSiao opened this issue 4 months ago • 4 comments

Summary

scripts/check-package.mjs rejects a valid npm tarball on Windows when the system tar command emits CRLF line endings for tar -tvzf.

The validation uses a multiline regular expression directly on the complete listing. In JavaScript, both CR and LF are line terminators for multiline anchors, so ^ can match between the \r and \n. The following \n is then tested as if it were the first character of a new line and triggers the non-regular-entry error.

Affected version and environment

  • Released package: @openai/[email protected]
  • Confirmed still present on current main at f22d4a36f26d16287bcdfd707b369116e02a08c3
  • Microsoft Windows NT 10.0.19045.0
  • PowerShell 7.6.3
  • Node.js 24.18.0
  • pnpm 11.17.0
  • bsdtar 3.5.2 / libarchive 3.5.2

Steps to reproduce

From the repository root:

cd sdk/typescript
corepack pnpm install --frozen-lockfile
corepack pnpm run build
corepack pnpm pack --pack-destination ../../dist
node scripts/check-package.mjs ../../dist/openai-codex-security-0.1.1.tgz

Observed error:

Error: npm tarball contains a non-regular entry (symbolic or hard link, device, or pipe).
    at scripts/check-package.mjs:185

I then captured the exact tar --ignore-zeros -tvzf output and checked every non-empty line. The generated archive contained 178 entries, and every listing line began with - or d; there were no links, devices, or pipes.

The package installation smoke test also passed:

Validated installed @openai/[email protected]: public import, CLI, and 94 bundled plugin files.

A minimal diagnostic using the same listing demonstrated the false match:

/^[^d-]/mu.exec(listing) matches the LF in the first CRLF sequence.

Expected behavior

A valid npm tarball containing only regular files and allowed directories should pass check-package.mjs regardless of whether the local tar command emits LF or CRLF.

Actual behavior

The validator reports a non-regular tar entry before the later code normalizes the same listing with split(/\r?\n/u).

Impact

Windows contributors using a CRLF-emitting tar implementation cannot run the repository's package-boundary validation locally, even though the generated package is valid and installable.

Relevant code

  • Current check: https://github.com/openai/codex-security/blob/f22d4a36f26d16287bcdfd707b369116e02a08c3/sdk/typescript/scripts/check-package.mjs#L183-L190
  • The code immediately below already creates normalized listingLines: https://github.com/openai/codex-security/blob/f22d4a36f26d16287bcdfd707b369116e02a08c3/sdk/typescript/scripts/check-package.mjs#L188-L198

PR #3 introduced the package-boundary checker and validated a Windows CI configuration, but its patch and review discussion do not cover a tar implementation that emits CRLF for verbose listings.

Suggested direction

Normalize the listing before checking entry types and reuse the normalized lines for both validations. For example:

const listingLines = listing.split(/\r?\n/u).filter(Boolean);
if (
  listingLines.some(
    (line) => !line.startsWith("d") && !line.startsWith("-"),
  )
) {
  throw new Error(
    "npm tarball contains a non-regular entry (symbolic or hard link, device, or pipe).",
  );
}

A focused regression test can pass a CRLF-formatted verbose listing with only regular files and assert that it is accepted.

ShawnSiao avatar Jul 29 '26 01:07 ShawnSiao

I independently reproduced this on Windows NT 10.0.26200.0, PowerShell 7.6.3, code page 936, Node.js 22.22.1, and the project-declared pnpm 11.9.0, against f22d4a36f26d16287bcdfd707b369116e02a08c3.

The real build and pack completed, but the baseline package check reported a non-regular entry. The same archive contained 179 verbose-listing entries, all starting with d or -; the multiline regex matched the LF inside the first CRLF sequence.

I tested a minimal implementation reference that creates listingLines first and performs the entry-type check on those normalized lines:

https://github.com/zhuyuy/codex-security/commit/6c1cc7f7578bc968f304d802d421f5c3e68abc71

Validation with Node.js 24.15.0 and pnpm 11.9.0 passed type checking, the full formatting check, build, and pack. The fixed checker then reported:

Validated ...openai-codex-security-0.1.1.tgz: 179 entries.

For this focused validation I passed plugin-files.json explicitly so the unrelated install smoke was not rerun; I am not claiming that smoke as part of this result. Sharing the fork commit as an implementation reference because external PRs cannot be imported into the canonical source.

zhuyuy avatar Jul 29 '26 11:07 zhuyuy

Fixed by #436, which parses native tar listings by complete lines, accepts both LF and CRLF, and continues rejecting non-regular archive entries.

rohanpoudel2 avatar Aug 21 '26 20:08 rohanpoudel2

I verified the fix in npm's current latest package, @openai/[email protected], on Windows.

Release evidence:

  • Published: 2026-08-23 02:58:33 UTC
  • npm gitHead: e71fefc0918d918fb5b79486d0d626d5ec2ea2f3
  • PR #436 merge commit: 17614f7765e75acc8878a747d42228c6e8ec9f18
  • The PR merge commit is an ancestor of the package gitHead.
  • The downloaded tarball's recomputed SHA-512 matched the npm registry integrity value.

Environment:

  • Windows NT 10.0.19045.0
  • PowerShell 7.6.5
  • Code page 65001
  • Node.js 24.18.0
  • bsdtar 3.5.2

Focused validation command:

$package = '<local-validation-dir>\openai-codex-security-0.1.17.tgz'
node sdk/typescript/scripts/check-package.mjs $package sdk/typescript/plugin-files.json

The checker and plugin-files.json used for this command were taken from the package gitHead shown above.

Result:

Validated ...openai-codex-security-0.1.17.tgz: 263 entries.

The command exited with status 0, and the original CRLF tar-listing false positive did not reproduce. This was the focused package check only; I did not rerun the install smoke or the full test suite for this release validation.

ShawnSiao avatar Aug 23 '26 05:08 ShawnSiao

Thanks for reporting this. I believe this is resolved by #436, which fixes CRLF handling in tar listings. Please feel free to reopen if you still run into it on the latest version.

mldangelo-oai avatar Aug 31 '26 14:08 mldangelo-oai