[PR #4204] [CLOSED] [Other] Image generation: hand the prompt to sd-cli in an owner-only file, not on its command line #4947

Closed
opened 2026-11-07 16:31:33 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4204
Author: @schmittcn
Created: 10/26/2026
Status: ❌ Closed

Base: main ← Head: pr/image-prompt-file


📝 Commits (1)

  • 74edc6a Image generation: hand the prompt to sd-cli in an owner-only file (--prompt-file), not on its command line, where every local account can read it (ps, /proc//cmdline); the fake sd-cli reads it; test (#4202)

📊 Changes

3 files changed (+39 additions, -12 deletions)

View changed files

📝 serve/fixtures/fake_sd_cli.py (+3 -1)
📝 serve/images.py (+15 -4)
📝 serve/test_images.py (+21 -7)

📄 Description

Problem and result

With an "images" section in the run config, serve/images.py started sd-cli with the request's prompt as a command-line argument (-p <prompt>). Every local account can read another process's arguments (ps, /proc/<pid>/cmdline) unless /proc is mounted with hidepid, so on a PC with several accounts private image prompts were readable while an image was generated (#4202).

Now the prompt goes to sd-cli as a file: write_prompt() writes it to prompt.txt in the job's own folder (created by mkdtemp, 0700) with mode 0600, and sd-cli gets --prompt-file <path>. The file is removed with the job's other files when the job ends, as before.

Fixes #4202. Found by a reviewer of a third-party Omarchy plugin that starts Strata models (omacom/omarchy-plugin-marketplace#12853).

Approach

--prompt-file came to stable-diffusion.cpp in 854bebfe0 (leejet/stable-diffusion.cpp#1693, 2026-06-22). The only commit Strata has pinned, SD_CPP_COMMIT 2988060 in tools/image/qimage.py (since a5b3b6c2), is 241 commits after it, so every sd-cli setup has built knows the flag. sd-cli reads the file as raw bytes into the prompt; it is written as UTF-8 without newline translation, so the prompt is unchanged.

serve/fixtures/fake_sd_cli.py now reads the prompt from --prompt-file, so the HTTP tests check that the prompt still arrives end to end.

Validation

Passed:

  • python -m serve.test_images: 20 tests OK (on main 4b9e05a2: OK before the change too). The new test_prompt_not_on_the_command_line checks the file's content (multi-line, non-ASCII), its mode 0600 (not on Windows), that the prompt is not in the command and that --prompt-file names the file.
  • The HTTP tests run the fake sd-cli, which reads the prompt from the file and encodes it into the image.

Not run:

  • A real sd-cli: image generation is not set up on this PC (Linux, RX 6900 XT). The flag's handling is from stable-diffusion.cpp's examples/common/common.cpp (on_prompt_file_arg).
  • Windows: os.open(..., 0o600) only sets the read-only bit there; the job folder's ACL is what protects it, as for the images themselves.

Limits

Only the prompt moves off the command line. The other arguments (size, seed, steps, file paths) stay there; none of them carry user content.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4204 **Author:** [@schmittcn](https://github.com/schmittcn) **Created:** 10/26/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/image-prompt-file` --- ### 📝 Commits (1) - [`74edc6a`](https://github.com/Niko1221/Strata/commit/74edc6a3be48210bfa9669ec02f5108ff1c44cce) Image generation: hand the prompt to sd-cli in an owner-only file (--prompt-file), not on its command line, where every local account can read it (ps, /proc/<pid>/cmdline); the fake sd-cli reads it; test (#4202) ### 📊 Changes **3 files changed** (+39 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `serve/fixtures/fake_sd_cli.py` (+3 -1) 📝 `serve/images.py` (+15 -4) 📝 `serve/test_images.py` (+21 -7) </details> ### 📄 Description ## Problem and result With an `"images"` section in the run config, `serve/images.py` started sd-cli with the request's prompt as a command-line argument (`-p <prompt>`). Every local account can read another process's arguments (`ps`, `/proc/<pid>/cmdline`) unless `/proc` is mounted with `hidepid`, so on a PC with several accounts private image prompts were readable while an image was generated (#4202). Now the prompt goes to sd-cli as a file: `write_prompt()` writes it to `prompt.txt` in the job's own folder (created by `mkdtemp`, 0700) with mode 0600, and sd-cli gets `--prompt-file <path>`. The file is removed with the job's other files when the job ends, as before. ## Related discussion Fixes #4202. Found by a reviewer of a third-party Omarchy plugin that starts Strata models (omacom/omarchy-plugin-marketplace#12853). ## Approach `--prompt-file` came to stable-diffusion.cpp in 854bebfe0 (leejet/stable-diffusion.cpp#1693, 2026-06-22). The only commit Strata has pinned, `SD_CPP_COMMIT` 2988060 in `tools/image/qimage.py` (since a5b3b6c2), is 241 commits after it, so every sd-cli setup has built knows the flag. sd-cli reads the file as raw bytes into the prompt; it is written as UTF-8 without newline translation, so the prompt is unchanged. `serve/fixtures/fake_sd_cli.py` now reads the prompt from `--prompt-file`, so the HTTP tests check that the prompt still arrives end to end. ## Validation **Passed:** - `python -m serve.test_images`: 20 tests OK (on `main` 4b9e05a2: OK before the change too). The new `test_prompt_not_on_the_command_line` checks the file's content (multi-line, non-ASCII), its mode 0600 (not on Windows), that the prompt is not in the command and that `--prompt-file` names the file. - The HTTP tests run the fake sd-cli, which reads the prompt from the file and encodes it into the image. **Not run:** - A real sd-cli: image generation is not set up on this PC (Linux, RX 6900 XT). The flag's handling is from stable-diffusion.cpp's `examples/common/common.cpp` (`on_prompt_file_arg`). - Windows: `os.open(..., 0o600)` only sets the read-only bit there; the job folder's ACL is what protects it, as for the images themselves. ## Limits Only the prompt moves off the command line. The other arguments (size, seed, steps, file paths) stay there; none of them carry user content. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:31:33 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4947
No description provided.