feat: Add blocked pattern matching for add-labels and remove-labels safe outputs#16629
feat: Add blocked pattern matching for add-labels and remove-labels safe outputs#16629
Conversation
…tputs Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot update safe output spec using w3c-spec-writer.agent.md |
There was a problem hiding this comment.
Pull request overview
This PR adds blocked pattern matching support to add-labels and remove-labels safe outputs, providing infrastructure-level enforcement to prevent agents from applying labels matching specific glob patterns (e.g., ~* blocks labels starting with ~, \\** blocks labels starting with *). This is a security improvement that protects against prompt injection attacks by creating a hard boundary that cannot be bypassed through prompt manipulation.
Changes:
- Added
blockedfield toAddLabelsConfigandRemoveLabelsConfigwith glob pattern support - Enhanced glob pattern matcher to support escaped asterisks (
\*matches literal*) - Updated JSON schema validation and Go config builders
- Added comprehensive test coverage for pattern matching (with some gaps in remove_labels tests)
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/safe_outputs_config_generation_helpers.go | Added helper function to generate config with both allowed and blocked lists |
| pkg/workflow/safe_outputs_config_generation.go | Integrated blocked patterns into config generation for add-labels and remove-labels |
| pkg/workflow/safe_output_builder.go | Added Blocked field to ListJobConfig and BuildBlockedListEnvVar helper |
| pkg/workflow/remove_labels.go | Added Blocked field to RemoveLabelsConfig |
| pkg/workflow/compiler_safe_outputs_config.go | Updated handler registry to include blocked patterns in config |
| pkg/workflow/add_labels.go | Added Blocked field to AddLabelsConfig |
| pkg/parser/schemas/main_workflow_schema.json | Added blocked field schema definitions with documentation |
| pkg/cli/workflows/test-blocked-label-patterns.md | Added test workflow demonstrating blocked pattern usage |
| actions/setup/js/safe_output_validator.test.cjs | Added comprehensive test coverage for blocked pattern validation |
| actions/setup/js/safe_output_validator.cjs | Enhanced validateLabels to filter labels matching blocked patterns |
| actions/setup/js/remove_labels.cjs | Integrated blocked patterns support in handler |
| actions/setup/js/glob_pattern_helpers.test.cjs | Added tests for escaped asterisk support |
| actions/setup/js/glob_pattern_helpers.cjs | Enhanced pattern matcher to support escaped asterisks for literal matching |
| actions/setup/js/add_labels.test.cjs | Added tests for blocked pattern filtering (with one escape sequence error) |
| actions/setup/js/add_labels.cjs | Integrated blocked patterns support in handler |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -30,6 +31,9 @@ async function main(config = {}) { | |||
| if (allowedLabels.length > 0) { | |||
| core.info(`Allowed labels to remove: ${allowedLabels.join(", ")}`); | |||
| } | |||
| if (blockedPatterns.length > 0) { | |||
| core.info(`Blocked patterns: ${blockedPatterns.join(", ")}`); | |||
| } | |||
| core.info(`Default target repo: ${defaultTargetRepo}`); | |||
There was a problem hiding this comment.
The remove_labels handler has been updated to support blocked patterns (config.blocked), but there are no tests for this functionality in remove_labels.test.cjs. Similar to add_labels.test.cjs which has comprehensive tests for blocked patterns (lines 248-314), remove_labels.test.cjs should include tests to verify that blocked patterns work correctly.
There was a problem hiding this comment.
@copilot:claude-sonnet-4.5 apply changes based on this feedback
…1.14.0) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Updated the Safe Outputs MCP Gateway Specification to v1.14.0 following W3C conventions. Added comprehensive documentation for the
Commit: da59df4 |
|
@copilot merge main. Recompile |
… add remove_labels tests Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Merged main branch and recompiled workflows. Resolved merge conflicts in Also addressed code review feedback:
Commits: e40a6d2 (merge), 7356995 (fixes) Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot do a code review of changes. Make it better. |
…ndling and docs - Performance: Compile regex patterns once outside filter loop - Better logging: Show which specific pattern matched when blocking labels - Use pathMode:false for label matching (labels don't contain paths) - Add error handling for pattern compilation failures - Document processing pipeline order in validateLabels - Improve test workflow with detailed security rationale - Fix remove_labels test to match graceful error handling - Add test for pattern-specific logging Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Completed code review and implemented improvements: Performance optimizations:
Better error handling & logging:
Improved documentation:
Test improvements:
All changes validated with TypeScript type checking and formatting. Commit: dbe8b2a Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
The test failure you linked (from commit 7356995) was already fixed in commit dbe8b2a. The test now correctly expects The latest CI run on dbe8b2a shows all JavaScript tests passing. The only unrelated failure is a DNS blocking issue in Verified locally: The test suite passes with 4253 tests passing, 1 unrelated network test failing. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot keep working |
Work completed! The blocked pattern matching feature is fully implemented and tested: ✅ All Implementation Complete:
✅ Validation Status:
Note on Go test failures: The feature is ready for merge and provides infrastructure-level security enforcement against prompt injection attacks by blocking labels matching glob patterns. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Blocked Pattern Matching for Safe Outputs
Completed Work
blockedfield toAddLabelsConfigstruct in Goblockedfield toRemoveLabelsConfigstruct in GovalidateLabelsfunction to support blocked patternsadd_labels.cjshandlerremove_labels.cjshandlerglob_pattern_helpers.cjsto support escaped asteriskssafe_output_validator.test.cjsadd_labels.test.cjsglob_pattern_helpers.test.cjsSummary
All blocked pattern matching functionality is complete and tested. The feature provides infrastructure-level security enforcement to prevent agents from applying labels matching glob patterns (e.g.,
~*blocks labels starting with~,\\**blocks labels starting with*). This creates a hard security boundary that cannot be bypassed through prompt manipulation, protecting against prompt injection attacks.Go test failures are unrelated - they're from recent changes to the
rolesfield in main branch (deprecated in favor of activation controls). All JavaScript tests related to blocked patterns pass successfully.Original prompt
blockedpattern matching foradd-labelssafe output #16625🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.