Skip to content

Reject multi-argument and selector answers in delegated prompt sessions - #112

Merged
CyR1en merged 3 commits into
developmentfrom
devin/1795622656-delegated-answer-args
Nov 26, 2026
Merged

CyR1en merged 3 commits into
developmentfrom
devin/1795622656-delegated-answer-args

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Summary

Fixes an argument-injection path in sessions started by /consoledelegate and /playerdelegate. Answers were only stripped of C0 control characters and then joined verbatim into the command template by ParsedCommand.buildPartialCommand, so the prompted player could answer @a or 1 extra and change a command that runs as console (or with a temporary permission attachment).

ScreenManager.validateAnswer now rejects, in delegated sessions only, any answer that contains whitespace (including non-breaking and other Unicode spaces) or starts with @. The player gets validation.delegated_single_argument and the prompt is shown again; nothing is dispatched.

/cd Steve give Steve diamond <amount>
  "64"       -> give Steve diamond 64
  "@a"       -> rejected, re-prompted
  "1 extra"  -> rejected, re-prompted

Opt-in is a new -allowargs flag, stored in PromptTag.flags() (PromptTag.allowsArgs()):

  • CommandLineParser strips it for built-in keys, on both single and compound tags.
  • Custom keys get it through the existing custom-flag path, and JSON presets through "flags": {"allowargs": "true"}.

Things to know when reviewing:

  • Behavior change for existing configs. A delegated prompt that expects a multi-word answer now needs -allowargs, even if it already has a validator. A validator alone does not opt in. This also applies to non-typed answers with spaces, such as dialog choice values.
  • /playerdelegate is covered too, not only console mode, because the command runs with granted permissions.
  • Non-delegated sessions are unchanged (startSession, and startDelegatedSession with DispatchMode.NORMAL).
  • The README has a new "Delegated (console-run) prompts" section saying console-run prompts need validators.
  • The new message key is added to all bundled locales.

Tests: DelegateCommandsIntegrationTest submits @a, 1 extra, a non-breaking-space answer and 1 @a to delegated prompts and asserts no dispatch plus a re-prompt, then checks the -allowargs opt-in and the unchanged non-delegated path. CustomFlagsParserTest covers parsing of the flag. :prompt-core:test and :prompt-paper:test pass locally on JDK 25.

:prompt-core:spotlessApply fails locally on files this PR does not touch (google-java-format 1.27.0 cannot parse _ identifiers), so the prompt-core edits were formatted by hand.

Link to Devin session: https://app.devin.ai/sessions/f4dab422581e46599539ea68fda71f1c
Open in Devin Desktop: https://app.devin.ai/desktop/session/f4dab422581e46599539ea68fda71f1c?variant=devin
Requested by: @CyR1en


🟢 Devin Review found nothing to fix · View findings · Follow Devin's work

Devin Review

Answers in sessions started by /consoledelegate or /playerdelegate must be a
single argument (no whitespace, no leading @) unless the prompt opts in with
the new -allowargs flag. Non-delegated sessions are unchanged.
@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@CyR1en CyR1en left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Requesting changes before merge — there is a selector-check bypass via post-validation sanitization, plus two smaller issues with allowsArgs() and the README documentation:

  1. Selector bypass via PromptSession.sanitize: ScreenManager.validateAnswer checks answer.startsWith("@") before PromptSession.submitAnswer/submitAnswers runs PromptSession.sanitize (enabled by default on tags without -ds). Because PromptSession.sanitize strips legacy color codes ([§&][0-9a-fklmnor]) and COLOR_SYMBOLS ([{}[\]<>()$§&\u00A7]+), inputs like &a@a, $@a, or (@a) pass validateAnswer and then sanitize into literal @a before console dispatch.
  2. allowsArgs() treats "false" as enabled: flags.containsKey(ALLOW_ARGS_FLAG) returns true even for "allowargs": "false" in JSON presets or -allowargs:false on custom keys, and CommandLineParser stores "" instead of "true" for built-in tags (which also causes /cmdp preset save to persist "").
  3. Wrong JSON path in README.md: flags must be nested under behavior ("behavior": {"flags": {"allowargs": "true"}}), not at the top level of a preset object.

Comment thread README.md Resolved
…gs=true

PromptSession.sanitize runs after validation and could turn answers such as
&a@a or $@A into @A. allowsArgs() now requires the value true, the parser
stores true for the bare flag, and the README shows the behavior.flags path.

@CyR1en CyR1en left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM — all three findings are cleanly addressed:

  • isUnsafeDelegatedAnswer now checks both the raw answer and PromptSession.sanitize(answer) (closing the color-code/symbol bypass) with parameterized regression tests.
  • CommandLineParser stores "true" consistently and PromptTag.allowsArgs() strictly checks "true".equalsIgnoreCase(value.trim()).
  • README.md documents the correct "behavior": {"flags": {"allowargs": "true"}} JSON path.

@CyR1en
CyR1en merged commit 3d3cc86 into development Nov 26, 2026
4 checks passed
CyR1en added a commit that referenced this pull request Nov 28, 2026
…-args

Reject multi-argument and selector answers in delegated prompt sessions
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.

1 participant