← Back to Pull requests

use-trusted-publishing: read every argument of PowerShell commands #2431

Open
LucaCappelletti94 opened this pull request with 76 lines diff across 5 files
View on GitHub
LucaCappelletti94 LucaCappelletti94 commented on Oct 03, 2026 09:21 UTC
Author

Pre-submission checks

Please check these boxes:

  • Mandatory: This PR corresponds to an issue (if not, please create

  • one first).

  • Having read the [AI policy], I hereby disclose the use of an LLM or other

  • AI coding assistant in the creation of this PR. PRs will not be rejected
    for using AI tools, but will be rejected for undisclosed use or
    use that violates the policy.

    [AI policy]: https://github.com/zizmorcore/.github/blob/main/AI_POLICY.md

    If a checkbox is not applicable, you can leave it unchecked.

    Summary

    Fixes #2430.

    The PowerShell query from #1357 yielded one match per argument and skipped command_parameter nodes, so is_publish_command never saw publish and --dry-run together. It now captures the whole command_elements node and reads both plain arguments and parameters from it, which also catches dotnet nuget push and similar commands under pwsh.

    cargo publish --features=foo --dry-run stays reported because of #2389.

    Test Plan

    PowerShell cases added to the cargo-publish.yml and nuget-push.yml inputs.

    <!-- IMPORTANT: Do not delete the following lines. -->
    <!-- @@NUDNIK NEUTRALIZER@@ -->

    Diff: 76 lines (+69 / -7) across 5 files Reviewer: woodruffw Review duration: 12393m
    All Vouch review confidence checks passed
    Residual risk 0.03 = Change Risk (0.40) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 76 lines diff across 5 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.94 · 5 substantive comment(s)
    0.94
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    92%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.260
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    8 items
    woodruffw woodruffw commented on code on Oct 04, 2026 01:37 UTC
    Code Review
    crates/zizmor/src/audit/use_trusted_publishing.rs:1
    @@ -392,9 +394,20 @@ impl UseTrustedPublishing {
                     .captures()
                     .iter()
                     .filter(|cap| cap.index == args)
    -                .map(|cap| {
    -                    cap.node
    -                        .utf8_text(run.as_bytes())
    +                .flat_map(|cap| {

    I'm not sure this approach is what we want: it effectively pierces the abstraction across different tree-sitter grammars, which also means it'll break in hard to predict ways if any other grammar happens to add node kinds that match these PowerShell names. Is there a way to fix the query itself so that it captures what we're expecting here?

    The answer might be "no" without a fix to https://github.com/airbus-cert/tree-sitter-powershell/issues/46

    woodruffw woodruffw requested changes on Oct 04, 2026 01:38 UTC
    Changes Requested Reviewer

    Requested changes.

    LucaCappelletti94 LucaCappelletti94 commented on code on Oct 04, 2026 06:00 UTC
    Code Review
    crates/zizmor/src/audit/use_trusted_publishing.rs:1
    @@ -392,9 +394,20 @@ impl UseTrustedPublishing {
                     .captures()
                     .iter()
                     .filter(|cap| cap.index == args)
    -                .map(|cap| {
    -                    cap.node
    -                        .utf8_text(run.as_bytes())
    +                .flat_map(|cap| {

    I will extend the test suite with a few adversarial cases and see what is the cleanest general solution I can come up with. I will also spend a second looking at upstream, in case by any chance that could be the first domino to push down. Given the issue is only a few months old and not one of the pre-covid era, I hope it may be still there only because of it being not too important and not because it is cursed.

    LucaCappelletti94 LucaCappelletti94 commented on code on Oct 04, 2026 17:04 UTC
    Code Review
    crates/zizmor/src/audit/use_trusted_publishing.rs:1
    @@ -392,9 +394,20 @@ impl UseTrustedPublishing {
                     .captures()
                     .iter()
                     .filter(|cap| cap.index == args)
    -                .map(|cap| {
    -                    cap.node
    -                        .utf8_text(run.as_bytes())
    +                .flat_map(|cap| {

    Ok so I spend a bit more time rabbit-holing upstream than I care to admit, set up a differential fuzzer against the original windows C# lexer and it is a bit of a disaster, it found a vast amount of errors. I believe that this problem I reported here yesterday and patched in an arguably not sufficiently general way is only one of several possible corner cases that the parser upstream does not handle correctly.

    I am unsure regarding how to proceed, as clearly the tree-sitter-powershell needs extensive improvement and I absolutely do not have the bandwidth to fix it.

    woodruffw woodruffw commented on code on Oct 04, 2026 17:34 UTC
    Code Review
    crates/zizmor/src/audit/use_trusted_publishing.rs:1
    @@ -392,9 +394,20 @@ impl UseTrustedPublishing {
                     .captures()
                     .iter()
                     .filter(|cap| cap.index == args)
    -                .map(|cap| {
    -                    cap.node
    -                        .utf8_text(run.as_bytes())
    +                .flat_map(|cap| {

    Yeah, that was unfortunately the conclusion I came to as well when I saw the --foo=bar issue -- the grammar does not appear to follow Microsoft's own documented grammar closely, and has lots of gaps.

    I think long term I'm going to replace tree-sitter-powershell with zizmor-tree-sitter-powershell, which will almost certainly just be written by an LLM and reviewed by me with a bunch of known-answer tests and fuzz/differential testing.

    woodruffw woodruffw commented on code on Oct 04, 2026 17:35 UTC
    Code Review
    crates/zizmor/src/audit/use_trusted_publishing.rs:1
    @@ -392,9 +394,20 @@ impl UseTrustedPublishing {
                     .captures()
                     .iter()
                     .filter(|cap| cap.index == args)
    -                .map(|cap| {
    -                    cap.node
    -                        .utf8_text(run.as_bytes())
    +                .flat_map(|cap| {

    (But thank you for looking into it! I greatly appreciate the effort you've put in, especially setting up a differential test harness for the upstream.)

    LucaCappelletti94 LucaCappelletti94 commented on code on Oct 04, 2026 17:36 UTC
    Code Review
    crates/zizmor/src/audit/use_trusted_publishing.rs:1
    @@ -392,9 +394,20 @@ impl UseTrustedPublishing {
                     .captures()
                     .iter()
                     .filter(|cap| cap.index == args)
    -                .map(|cap| {
    -                    cap.node
    -                        .utf8_text(run.as_bytes())
    +                .flat_map(|cap| {

    Yeah I hope that tool will come handy

    Reviewers
    Assignees
    LucaCappelletti94 LucaCappelletti94
    Labels
    risk: low confidence: 92.4% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.8% (MEDIUM) · Higher = larger blast radius
    39.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 92.4% · Lower = rushed or shallow review
    92.4%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3% · Safe to merge
    3%