eugenegujing opened a new issue, #9212:
URL: https://github.com/apache/texera/issues/9212
### What happened?
The frontend sends the PVE websocket's `packages` query parameter as a JSON
array:
```typescript
//
frontend/src/app/workspace/service/virtual-environment/virtual-environment.service.ts:104
const query = encodeURIComponent(JSON.stringify(packages));
```
The backend does not decode that JSON. It strips the outer brackets, splits
the whole value on every comma, and deletes every double quote:
```scala
//
amber/src/main/scala/org/apache/texera/web/resource/pythonvirtualenvironment/PveWebsocketResource.scala:79-88
val packages =
params
.getOrDefault("packages", java.util.List.of("[]"))
.get(0)
.stripPrefix("[")
.stripSuffix("]")
.split(",")
.toList
.map(_.replace("\"", "").trim)
.filter(_.nonEmpty)
```
A comma inside one requirement is treated as an array separator.
`example>=1,<2` is a single valid pip requirement with two version specifiers,
but it reaches `PveManager.installUserPackages` as two entries, so pip is
invoked for `example>=1` and then for the invalid fragment `<2`:
```text
Wire value: ["example>=1,<2"]
Decoded as: List("example>=1", "<2")
```
The same code also deletes quote characters instead of decoding JSON
escapes, and accepts a truncated or non-array value without reporting anything.
### How to reproduce?
Reproduced on local `main` at 92e86d420 (build "dev") with a local computing
unit. Use a package that is not in the modal's "System Packages" list (for
example `tabulate`): the frontend skips a package it already finds in that list
before any websocket call.
1. Open a workflow with a running local computing unit, open the unit
dropdown and click the "Python Environment" (+) icon on the unit.
2. In the "Python Environments" modal, create or choose an environment
(letters and digits only, e.g. `myenv`).
3. Click "+" to add a package row and fill in Package `tabulate`, operator
`>=`, Version `0.8,<1`, then click OK.
4. Read "Pip Installation Output".
The Version box is free text and the frontend sends `name + operator +
version` as one array element, so `tabulate` / `>=` / `0.8,<1` becomes the
requirement `tabulate>=0.8,<1`, which is standard pip syntax for a version
range. The defect is not specific to that input: any element containing a comma
is split the same way, for example an extras requirement such as
`requests[security,socks]` typed in the Package box.
The frontend sent `packages=["tabulate>=0.8,<1"]` (URL-encoded) on the
websocket. The backend decoded it into `tabulate>=0.8` and `<1` and ran pip
twice:
```text
Installing user packages...
[PVE] Installing package: tabulate>=0.8
[pip] Collecting tabulate>=0.8
...
[pip] Successfully installed tabulate-0.10.0
[pip] install(tabulate>=0.8) finished with exit code 0
[PVE] Installing package: <1
[pip][ERR] ERROR: Invalid requirement: '<1'
[pip] install(<1) finished with exit code 1
[PVE][ERR] Failed to install package: <1
```
The installed-package list in the modal afterwards shows a row named
`tabulate>=0.8` with operator `==` and an empty version: the first fragment was
persisted as the package name.
Without a running stack, applying the expression above to the decoded value
`["tabulate>=0.8,<1"]` yields `List("tabulate>=0.8", "<1")`.
Screenshots (attached): `01-add-package-tabulate-ge-0.8-lt-1.jpg` (the
package row before OK),
`02-pip-log-first-fragment-tabulate-ge-0.8-installed.jpg` (first fragment
installed, wrong row in the package list),
`03-pip-log-second-fragment-lt-1-invalid-requirement.jpg` (second fragment
rejected by pip).
### Version/Branch
1.4.0-incubating-SNAPSHOT (main)
### Commit Hash (Optional)
_No response_
### What browsers are you seeing the problem on?
_No response_
### Relevant log output
```shell
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]