Skip to content

Commit 0be1f00

Browse files
committed
Add agnostic risk assessment for environment variable references
- Add IsAgnostic property to RiskAssessment and CommandRule models - Update RiskCombiner to defer to AI when regex assessment is agnostic - Change env var reference rules to be agnostic (defer to AI analysis) - Add env-var-reference-powershell and env-var-reference-bash rules - Regex no longer pre-judges env var usage, AI determines leak risk
1 parent 4c7966c commit 0be1f00

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

src/PostSharp.Engineering.BuildTools/Mcp/Models/CommandRule.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,10 @@ public sealed class CommandRule
4040
/// If null, the rule applies whenever the pattern matches.
4141
/// </summary>
4242
public Func<CommandContext, bool>? Condition { get; init; }
43+
44+
/// <summary>
45+
/// Gets a value indicating whether this rule is agnostic (defers to AI analysis).
46+
/// When true, matching this rule will not influence the risk assessment - only AI will determine risk.
47+
/// </summary>
48+
public bool IsAgnostic { get; init; }
4349
}

src/PostSharp.Engineering.BuildTools/Mcp/Models/RiskAssessment.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public sealed class RiskAssessment
4141
/// </summary>
4242
public string? RuleName { get; init; }
4343

44+
/// <summary>
45+
/// Gets a value indicating whether this assessment is agnostic (defers to AI analysis).
46+
/// When true, this regex-based assessment should be ignored and only AI assessment used.
47+
/// </summary>
48+
public bool IsAgnostic { get; init; }
49+
4450
public static RiskAssessment Default( string reason )
4551
{
4652
return new RiskAssessment

src/PostSharp.Engineering.BuildTools/Mcp/Services/CommandRules.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,30 @@ public static class CommandRules
290290
{
291291
Name = "export-env-variables",
292292
Pattern = new Regex( @"\$env:\w+\s*=", RegexOptions.IgnoreCase ),
293-
RiskLevel = RiskLevel.High,
293+
RiskLevel = RiskLevel.Low,
294+
Recommendation = Recommendation.Approve,
295+
Reason = "Setting environment variables - deferring to AI to determine if secrets are exposed",
296+
IsAgnostic = true
297+
},
298+
299+
new CommandRule
300+
{
301+
Name = "env-var-reference-powershell",
302+
Pattern = new Regex( @"\$env:\w+", RegexOptions.IgnoreCase ),
303+
RiskLevel = RiskLevel.Low,
304+
Recommendation = Recommendation.Approve,
305+
Reason = "Environment variable reference detected - deferring to AI to determine if leaked",
306+
IsAgnostic = true
307+
},
308+
309+
new CommandRule
310+
{
311+
Name = "env-var-reference-bash",
312+
Pattern = new Regex( @"\$\{?\w+\}?", RegexOptions.None ),
313+
RiskLevel = RiskLevel.Low,
294314
Recommendation = Recommendation.Approve,
295-
Reason = "Setting environment variables - ensure no secrets are being exposed"
315+
Reason = "Potential environment variable reference detected - deferring to AI analysis",
316+
IsAgnostic = true
296317
}
297318
};
298319

src/PostSharp.Engineering.BuildTools/Mcp/Services/RegexRuleEngine.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public Task<RiskAssessment> EvaluateAsync(
5858
Level = rule.RiskLevel,
5959
Recommendation = rule.Recommendation,
6060
Reason = rule.Reason,
61-
RuleName = rule.Name
61+
RuleName = rule.Name,
62+
IsAgnostic = rule.IsAgnostic
6263
} );
6364
}
6465

src/PostSharp.Engineering.BuildTools/Mcp/Services/RiskCombiner.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public static class RiskCombiner
1818
/// <returns>A combined risk assessment with the maximum risk level and most restrictive recommendation.</returns>
1919
public static RiskAssessment Combine( RiskAssessment aiAssessment, RiskAssessment regexAssessment )
2020
{
21+
// If regex assessment is agnostic, use only AI assessment
22+
if ( regexAssessment.IsAgnostic )
23+
{
24+
return aiAssessment;
25+
}
26+
2127
// Take the maximum (most restrictive) risk level
2228
var maxLevel = (RiskLevel) Math.Max( (int) aiAssessment.Level, (int) regexAssessment.Level );
2329

0 commit comments

Comments
 (0)