Skip to content

Fix a shadow remote code execution#1404

Closed
Tednoob17 wants to merge 2 commits intogoogle:mainfrom
Tednoob17:main
Closed

Fix a shadow remote code execution#1404
Tednoob17 wants to merge 2 commits intogoogle:mainfrom
Tednoob17:main

Conversation

@Tednoob17
Copy link
Copy Markdown

Fixes ##1403 / suggests an improvement
This was discovered during a security audit of zx. Although Google VRP determined it doesn't meet their internal severity threshold for a 'security bug' tracking, it remains a functional flaw that allows unintended code execution. This PR resolves the parsing discrepancy.

 The transformMarkdown function fails to recognize standalone Carriage Return (\r) characters as line terminators. When processing Markdown, it incorrectly wraps text containing \r into a single JavaScript comment. Node.js, however, treats \r as a valid line break, causing any code following the \r to be executed instead of remaining commented out. This allows arbitrary code execution hidden within plain text sections of Markdown files.
The vulnerability exists because of a mismatch between the parser's logic and the JavaScript engine's (Node.js) specification.
@Tednoob17
Copy link
Copy Markdown
Author

Since this involves unintended code execution via a parsing bypass, would you be open to opening a GitHub Security Advisory for this?

Comment thread src/md.ts
let codeBlockEnd = ''
let prevLineIsEmpty = true
for (const line of bufToString(buf).split(/\r?\n/)) {
for (const line of bufToString(buf).split(/\r?\n|\r|\u2028|\u2029/)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's simplify a bit: /\r\n|[\n\r\u2028\u2029]/

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you test it ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it work

@Tednoob17
Copy link
Copy Markdown
Author

cool @antongolub and it's possible to have a GitHub Security Advisory for this?

@antongolub
Copy link
Copy Markdown
Collaborator

RCE is a feature, code verification before running is a mandatory requirement. We'll add a clear warning for this to the docs.

@Tednoob17
Copy link
Copy Markdown
Author

yes but even a good code review leads to RCE, even if the code is commented out, execution is still possible.

@Tednoob17
Copy link
Copy Markdown
Author

i update my fix, thanks @antongolub

@Tednoob17
Copy link
Copy Markdown
Author

Please i program yo disclose my report from google vrp to my blog tomorrow can you merge a fix ? @antongolub @moQuez @precision @azu ?

@antongolub
Copy link
Copy Markdown
Collaborator

@Tednoob17

Follow the template, plz. https://github.com/google/zx/blob/main/.github/PULL_REQUEST_TEMPLATE.md
It cannot be merged as is.

@Tednoob17
Copy link
Copy Markdown
Author

  • During my npm run build and npm run test i see that :
}
 [WARNING] "import.meta" is not available in the configured target environment ("es2015") and will be empty [empty-import-meta]

    src/cli.ts:263:20:
      263    metaurl: string = import.meta.url,
                               ~~~~~~~~~~~
  • During npm i i see this :
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported

added 546 packages, and audited 547 packages in 25s

132 packages are looking for funding
  run `npm fund` for details

1 moderate severity vulnerability

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

It normal ? I can push if all https://github.com/google/zx/blob/main/.github/PULL_REQUEST_TEMPLATE.md are ok ?

@Tednoob17
Copy link
Copy Markdown
Author

Fixes #issue / suggests an improvement

for (const line of bufToString(buf).split(/\r?\n|\r|\u2028|\u2029/)) {

Note : that a npm run test work only with this NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt npm run test becase of fetch tests required TLS bypass locally due to environment-specific CA resolution issues, but will pass in CI.

@Tednoob17
Copy link
Copy Markdown
Author

cc @antongolub

@Tednoob17
Copy link
Copy Markdown
Author

Hi, it's a disclose day, i wait you. @antongolub

@antonmedv antonmedv closed this Feb 20, 2026
@google google deleted a comment from Tednoob17 Feb 20, 2026
@google google locked as resolved and limited conversation to collaborators Feb 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants