Skip to content

Fix #1213: pass JAVA_OPTS as argv array instead of interpolating it into a shell string - #1293

Open
Inf1mum wants to merge 5 commits into
OpenAPITools:masterfrom
Inf1mum:fix/1213-java-opts-shell-split
Open

Inf1mum wants to merge 5 commits into
OpenAPITools:masterfrom
Inf1mum:fix/1213-java-opts-shell-split

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #1213.

pass-through.service.ts joined the java command, including JAVA_OPTS, into a single string and spawned it with shell: true, so shell metacharacters in JAVA_OPTS changed what was executed. A value like -Dhttp.nonProxyHosts=127.*|localhost|*.local was read as a shell pipe and the CLI failed with Error: 'localhost' is not recognized as an internal or external command. The help/completion discovery probed at startup goes through the same code, so every CLI invocation crashed before a command even ran.

What changed

  • cmd() now returns an argv array instead of a shell string: ['java', ...splitArgs(JAVA_OPTS), '-jar', cliPath].
  • JAVA_OPTS is split by a small tokenizer that respects quotes and backslash escapes, so a pipe in it reaches java as one argument.
  • passThrough() and the help/completion discovery spawn with an args array and shell: false.

version-manager.service.ts still spawns docker pull/docker rmi via a shell string, as there is no user-controlled input there.

Tests

JAVA_OPTS='-Dhttp.nonProxyHosts=127.*|localhost' openapi-generator-cli help failed before the change and prints the usage with exit code 0 after it (checked against the built CLI). pass-through.service.spec.ts mocks spawn and asserts the exact argv arrays, including an unquoted pipe and quoted JAVA_OPTS. npx nx test generator-cli: 255 tests passing; npx nx lint generator-cli clean.


Summary by cubic

Fixes every CLI command crashing when JAVA_OPTS contains shell-special characters. The java command was built by interpolating JAVA_OPTS into a single string and spawned with shell: true, so a legitimate value like -Dhttp.nonProxyHosts=127.*|localhost was parsed as a pipe and failed startup; commands are now spawned as an argv array with shell: false. JAVA_OPTS is split by a tokenizer that respects quotes; unquoted backslashes are kept verbatim so Windows paths like C:\certs\client.jks survive, while backslash escapes are interpreted only inside double quotes.

Details

  • help/completion discovery now uses spawn with an args array instead of exec, and decodes output as utf8 so multi-byte characters split across chunks aren't rewritten as replacement characters.
  • Quoting jar/classpath paths is no longer needed since each path is a single argv entry.
  • version-manager docker pull/rm still uses shell strings since they contain no user-controlled input.

Written for commit 5091168. Summary will update on new commits.

View guided diff

JAVA_OPTS was interpolated into a single command string which was
spawned with shell: true. Characters that are meaningful to a shell -
most notably the pipe in -Dhttp.nonProxyHosts=127.*|localhost - were
therefore interpreted by the shell instead of reaching the java
process, breaking every command of the CLI (the command discovery via
exec failed the same way). Joining the args into one string also
triggered the Node.js DEP0190 deprecation warning.

The command is now built as a proper argv array: JAVA_OPTS is split
with a lightweight tokenizer that respects single/double quotes and
backslash escapes, and java (or docker) is spawned with shell: false.
This removes the whole class of shell-escaping problems.

Fixes OpenAPITools#1213

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

splitArgs treated a backslash outside of quotes as an escape character
the way a POSIX shell would, so a Windows path in JAVA_OPTS such as
C:\certs\client.jks reached java as C:certsclient.jks. Unquoted
backslashes are now kept verbatim; escaping is only interpreted inside
double quotes, where it follows the typical shell rules.
…A_OPTS

Within a double-quoted JAVA_OPTS segment a backslash closed nothing and
a following quote always terminated the segment, so -Dfoo="a\"b"
was passed to java as -Dfoo=a\b" with the trailing quote leaking out
of the quotes. A backslash inside double quotes now escapes exactly the
characters a typical shell lets it escape (quote, backslash, dollar,
backtick), while single-quoted segments keep treating the backslash as
a literal character.
The discovery of getCommands() was only exercised through a mock keyed
on the joined command line; the first two spawn calls were never
verified. The spec now asserts that help and completion are spawned on
the exact argv (java, jar path, sub command) with { shell: false }, and
the discovery beforeEach clears JAVA_OPTS so earlier tests cannot leak
options into the asserted argv.
The discovery run() accumulated stdout/stderr from Buffer chunks, so a
multi-byte utf8 character split across two chunks was decoded twice and
turned into replacement characters, corrupting non-ASCII help or error
text. Both streams now set utf8 encoding before the data handlers are
attached, and the spec asserts the encoding on the discovery streams.

This branch has not been deployed

No deployments
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.

[BUG] JAVA_OPTS is incorrectly evaluated

1 participant