Error-tolerant parse: recovered commands for unparseable input (deny-only use)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start by locating ParsedCommand and the existing exact parser projections for Commands, Clauses, IsUnparseable, and Syntax. Review how the parser handles unbalanced quotes, separators, assignments, and wrapper children before designing the recovered projection. Done means adding a clearly non-authoritative RecoveredCommands API that over-reports safely, preserves exact projections, and documents deny-only use.
由索引模型根据 Issue 内容生成。
描述
Problem
When ParsedCommand.IsUnparseable is true, Commands and Clauses are empty. A consumer then has no command words to check. Syntax can contain partial diagnostic evidence, but it has no stable projection that a consumer can use.
A security consumer must still find dangerous commands in input that the parser rejects. For example, a deny list must find rm -rf / in rm -rf / ; echo "unbalanced. Today each consumer must write its own raw-text splitter. Netclaw has one (LegacyShellTextScan, about 300 lines). It splits on whitespace outside quotes, guesses at list separators and wrapper children, and guesses a path style. That code is a second, weaker shell reader, and it drifts from the parser.
Proposal: error-tolerant parse with a separate recovered projection
Add a recovery result for unparseable input, similar to Roslyn error recovery. The parser returns what it could read, marked clearly as not authoritative.
Schematic API (names are open):
public sealed record ParsedCommand
{
// Unchanged: exact, fail-closed projections. Empty when IsUnparseable.
public IReadOnlyList<CommandOccurrence> Commands { get; }
public bool IsUnparseable { get; }
// New: populated only when IsUnparseable is true.
public IReadOnlyList<RecoveredCommand> RecoveredCommands { get; }
}
public sealed record RecoveredCommand(
IReadOnlyList<string> Words, // quote-removed words, best effort
SourceRange Range, // where in Source
RecoveryReason Reason); // unbalanced quote, unknown construct, ...
Contract
CommandsandClauseskeep their current meaning. Recovery never adds to them.RecoveredCommandsis for deny-only use: deny lists, protected-path checks, and audit. The XML docs must say that a consumer must not allow, approve, or grant anything from a recovered command.- Recovery must over-report, not under-report. If the parser cannot decide whether text is one command or two, it returns both readings.
- Recovery includes wrapper children when the wrapper text is readable (
bash -c "...",sh -c '...',pwsh -Command ...). - Recovery uses the same grammar code as the exact parser where it can. A second tokenizer is not the goal.
Examples
Positive (recovered words exist):
rm -rf / ; echo "unbalancedrecoversrm -rf /andecho unbalanced.X=1 Y=2 netclaw daemon stop(until #189 lands) recoversnetclaw daemon stopwith the assignments skipped.bash -c "shutdown now; echo 'xrecoversshutdown nowfrom the wrapper child.
Negative:
- Input that parses exactly has an empty
RecoveredCommands. The exact projection is the only source of truth. - A recovered command never appears in
Commands, sols ; echo "xstays unparseable and does not become an approvedls.
Consumer plan
Netclaw will check recovered commands against its hard-deny list and protected-path hints, and then delete LegacyShellTextScan. Netclaw keeps its policy data (deny lists, path hints). Only the grammar work moves here.
- 主要语言
- C#
- 星标
- 15
- 派生
- 0
- 平均合并
- 9 小时 54 分钟
- 30 天内合并 PR
- 40
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Aaronontheweb/ShellSyntaxTree 的其他 Issue
-
Command words: restore the beta.19 verb-slot rule可能已有人在做 @Aaronontheweb 今天认领。 未关闭
难度 3/5 1-2 天 新手友好度 35/100
Aaronontheweb/ShellSyntaxTree#240 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
Aaronontheweb/ShellSyntaxTree#236 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 55/100
Aaronontheweb/ShellSyntaxTree#235 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 38/100
Aaronontheweb/ShellSyntaxTree#227 · 1 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 35/100
Aaronontheweb/ShellSyntaxTree#71 · 1 条评论 ·
维护者通常 1 天内回复
查看 Aaronontheweb/ShellSyntaxTree 的全部 Issue
相似的 Issue
-
S: Untriaged
难度 2/5 1-3 小时 新手友好度 78/100
space-wizards/space-station-14#46357 ·
维护者通常 1 天内回复
-
Versioning_oM: Remove unneeded depeendecy on Test_oM可能已有人在做 @IsakNaslundBh 今天认领。 未关闭type:bug type:compliance
难度 2/5 1 小时以内 新手友好度 85/100
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 66/100
MicrosoftLearning/PL-400_Microsoft-Power-Platform-Developer#231 ·
-
难度 2/5 1-3 小时 新手友好度 66/100
joinrpg/joinrpg-net#5313 ·
维护者通常 1 天内回复