Error-tolerant parse: recovered commands for unparseable input (deny-only use)
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- C#
- Sterne
- 15
- Forks
- 0
- Ø Merge
- 9 Std. 54 Min.
- Gemergte PRs (30 T.)
- 40
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus Aaronontheweb/ShellSyntaxTree
-
Command words: restore the beta.19 verb-slot ruleEvtl. vergeben @Aaronontheweb hat das heute übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
Aaronontheweb/ShellSyntaxTree#240 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
Aaronontheweb/ShellSyntaxTree#236 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
Aaronontheweb/ShellSyntaxTree#235 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 38/100
Aaronontheweb/ShellSyntaxTree#227 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
Aaronontheweb/ShellSyntaxTree#71 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in Aaronontheweb/ShellSyntaxTree
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
MicrosoftLearning/PL-400_Microsoft-Power-Platform-Developer#231 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
joinrpg/joinrpg-net#5313 ·
Maintainer antworten meist innerhalb von 1 Tag
-
[12.x] FixIncorrectOwnerIdRelationships can delete legitimate library roots when UserView shares the same pathEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
Maintainer antworten meist innerhalb von 1 Tag