Skip to content

fix: resolve CI lint errors and dependency confusion allowlist#732

Merged
imran-siddique merged 1 commit intomicrosoft:mainfrom
imran-siddique:fix/ci-green
Apr 2, 2026
Merged

fix: resolve CI lint errors and dependency confusion allowlist#732
imran-siddique merged 1 commit intomicrosoft:mainfrom
imran-siddique:fix/ci-green

Conversation

@imran-siddique
Copy link
Copy Markdown
Member

Fixes both CI failures on main:

  1. lint (agent-compliance): removed trailing whitespace (W293) and unused imports (F401) in cli/main.py and supply_chain.py
  2. dependency-scan: added all missing packages to REGISTERED_PACKAGES and REGISTERED_NPM_PACKAGES allowlists

Both checks verified passing locally.

- Remove trailing whitespace in agent-compliance cli/main.py
- Remove unused imports (os, field) in supply_chain.py
- Add all missing packages to REGISTERED_PACKAGES and
  REGISTERED_NPM_PACKAGES in check_dependency_confusion.py

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@imran-siddique imran-siddique merged commit e97a9b4 into microsoft:main Apr 2, 2026
22 of 23 checks passed
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

🤖 AI Agent: docs-sync-checker — Issues Found

📝 Documentation Sync Report

Issues Found

  • ⚠️ CHANGELOG.md — no entry for this change

Suggestions

  • 💡 Add an entry to CHANGELOG.md summarizing the fixes made in this PR:
    • Resolved CI lint errors by removing trailing whitespace and unused imports in cli/main.py and supply_chain.py.
    • Updated REGISTERED_PACKAGES and REGISTERED_NPM_PACKAGES allowlists in check_dependency_confusion.py to include missing packages.

Analysis

  1. New public APIs without docstrings: No new public APIs were introduced in this PR. No issues found.
  2. README sections out of date: No changes to behavior or functionality that would require updates to the README files. No issues found.
  3. CHANGELOG missing entries: The changes in this PR (fixing lint errors and updating allowlists) are not reflected in CHANGELOG.md. This should be addressed.
  4. Example code outdated: No changes to API signatures or behavior that would require updates to example code. No issues found.
  5. Type hints: No new public APIs were added, so no type hint issues were found.

Final Verdict

  • ❌ Documentation is not in sync. Please add a CHANGELOG.md entry for the changes in this PR.

@github-actions github-actions bot added the size/S Small PR (< 50 lines) label Apr 2, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

🤖 AI Agent: breaking-change-detector — Summary

🔍 API Compatibility Report

Summary

This pull request primarily addresses CI lint errors and updates dependency allowlists. After analyzing the provided diff, no breaking changes were detected in the public API of the microsoft/agent-governance-toolkit repository.

Findings

Severity Package Change Impact
agent-compliance Removed unused imports and trailing whitespace No impact on public API
dependency-scan Added missing packages to allowlists No impact on public API

Migration Guide

No migration steps are necessary as no breaking changes were identified.

Notes

  • The changes made in this pull request are limited to code cleanup (removing unused imports and trailing whitespace) and updating dependency allowlists. These modifications do not affect the public API or functionality of the packages.
  • No breaking changes detected.

Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Agent: code-reviewer

Review Summary

This pull request addresses two issues: fixing lint errors in the agent-compliance package and updating the dependency confusion allowlists for Python and NPM packages. While the changes are straightforward and aim to improve the CI pipeline's reliability, there are a few areas that warrant closer scrutiny, particularly around security and maintainability.


🔴 CRITICAL

  1. Dependency Confusion Allowlist Expansion:

    • Adding a large number of entries to the REGISTERED_PACKAGES and REGISTERED_NPM_PACKAGES allowlists increases the risk of overlooking potential dependency confusion vulnerabilities. While this is a necessary step to pass the CI, it is critical to ensure that all added entries are verified as legitimate and necessary.
    • Action Required:
      • Verify that all added packages are either internal or trusted third-party dependencies.
      • For internal packages, ensure they are not published to public package registries (e.g., PyPI or npm) to prevent malicious actors from squatting on these names.
      • Consider implementing automated validation to cross-check these entries against known internal repositories or private registries.
  2. Error Handling in handle_error Function:

    • The handle_error function in cli/main.py uses a generic Exception type for error handling. This could lead to unintended behavior if unexpected exceptions are caught and misclassified.
    • Action Required:
      • Replace Exception with more specific exception types to ensure that only anticipated errors are caught.
      • Log the actual exception details (e.g., stack trace) for debugging purposes, even if the error message presented to the user is generic.

🟡 WARNING

  1. Potential Breaking Changes in Dependency Allowlist:
    • The addition of new entries to the allowlist could inadvertently permit dependencies that were previously flagged as suspicious. This might lead to a less strict dependency scanning process.
    • Action Required:
      • Communicate these changes to the team to ensure that everyone is aware of the updated allowlist.
      • Document the rationale for each new entry in the allowlist to maintain auditability.

💡 SUGGESTIONS

  1. Code Cleanup in supply_chain.py:

    • The removal of the os import is appropriate since it is unused. However, consider running ruff with the --fix flag across the entire codebase to ensure all unused imports are removed consistently.
  2. Error Message Consistency:

    • In handle_error, the error messages for known and unknown exceptions are hardcoded. Consider using constants or an enumeration to define these messages for better maintainability and consistency.
  3. Automated Dependency Validation:

    • To prevent future issues with dependency confusion, consider implementing a CI step that validates the allowlist against your internal package registry and known trusted sources. This could help catch any accidental or malicious additions to the allowlist.
  4. Test Coverage:

    • Ensure that the changes to the handle_error function are covered by unit tests, especially for scenarios involving both known and unknown exceptions. This will help maintain the robustness of the error-handling logic.
  5. Documentation Update:

    • If the allowlist changes are significant, update the documentation to reflect the new entries and provide guidance on how to maintain the allowlist in the future.

Final Assessment

  • The changes in this PR address the immediate issues with CI failures, but the dependency allowlist expansion introduces potential risks that need to be mitigated.
  • The error-handling logic in handle_error should be refined to avoid catching generic exceptions and to improve debugging capabilities.
  • Additional safeguards and documentation updates are recommended to ensure long-term maintainability and security.

Please address the Critical and Warning items before merging this PR.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

🤖 AI Agent: security-scanner — Security Review of Pull Request

Security Review of Pull Request

Summary

This pull request addresses CI lint errors and updates the allowlist for dependency confusion checks. While the changes appear to be primarily focused on maintenance and housekeeping, they touch on critical areas such as dependency management and error handling. Below is a detailed security analysis of the changes.


Findings

1. Dependency Confusion Risk in Allowlist Expansion

Severity: 🔴 CRITICAL
Issue:
The addition of numerous packages to the REGISTERED_PACKAGES and REGISTERED_NPM_PACKAGES allowlists introduces a significant risk of dependency confusion attacks. By adding package names to these allowlists, the system may inadvertently permit malicious actors to publish similarly named packages to public repositories (e.g., PyPI or npm). If these packages are mistakenly fetched instead of the intended internal or trusted versions, it could lead to the execution of malicious code in downstream systems.
Attack Vector:
An attacker could register a package with one of the newly added names (e.g., agent-tool-registry, agent-control-plane, langsmith, etc.) on a public package repository. If the system's dependency resolution process mistakenly fetches the public package instead of the internal or trusted one, the attacker could execute arbitrary code.
Recommendation:

  • Verify the necessity of each added package. Ensure that all added packages are either internal or from trusted sources.
  • Enforce strict version pinning for all dependencies in the allowlist to prevent fetching malicious updates.
  • Implement additional validation to ensure that internal packages are always fetched from private repositories and not from public ones.
  • Consider automated monitoring for newly published packages on public repositories that match the names in the allowlist.

2. Potential Information Disclosure in Error Handling

Severity: 🟠 HIGH
Issue:
The handle_error function in cli/main.py outputs error messages in JSON format when output_json is True. While this is useful for debugging, there is a risk that sensitive information (e.g., stack traces, internal error messages) could be exposed to end-users or logged inappropriately.
Attack Vector:
If an attacker triggers an exception that is not properly sanitized, sensitive information such as file paths, system configurations, or even credentials could be exposed in the error message.
Recommendation:

  • Sanitize all error messages to ensure no sensitive information is included.
  • Log detailed error information securely (e.g., to a file or monitoring system) but provide only generic error messages to end-users.
  • Review the custom_msg parameter to ensure it cannot be manipulated by external input to inject sensitive information.

3. Potential for Unsafe Deserialization

Severity: 🟡 MEDIUM
Issue:
The json module is used in both cli/main.py and supply_chain.py for serialization and deserialization. While the json module is generally safer than alternatives like pickle, it is still susceptible to certain attacks if untrusted input is deserialized.
Attack Vector:
If untrusted JSON input is deserialized without validation, an attacker could craft malicious JSON payloads to exploit vulnerabilities in the application logic or cause denial-of-service (e.g., by sending deeply nested JSON objects).
Recommendation:

  • Validate all JSON input before deserialization to ensure it conforms to expected schemas.
  • Consider using libraries like jsonschema to enforce strict validation rules.

4. Unused Imports and Code Hygiene

Severity: 🔵 LOW
Issue:
The removal of unused imports (e.g., os and field) improves code hygiene but does not directly impact security. However, unused imports can sometimes indicate incomplete or abandoned functionality, which may lead to confusion or errors in the future.
Recommendation:

  • Ensure that the removal of unused imports does not inadvertently break any functionality.
  • Consider adding comments or documentation to clarify why certain imports are no longer needed.

Overall Assessment

While this pull request primarily addresses CI linting and dependency management, it introduces a critical risk of dependency confusion due to the expanded allowlist. Additionally, there are high-risk concerns related to error handling and medium-risk concerns around JSON deserialization. These issues should be addressed before merging the pull request.


Actionable Recommendations

  1. Dependency Confusion:

    • Audit the newly added packages in the allowlist to ensure they are necessary and from trusted sources.
    • Enforce strict version pinning for all dependencies in the allowlist.
    • Implement safeguards to ensure internal packages are fetched from private repositories.
    • Set up monitoring for public repositories to detect potential dependency confusion attacks.
  2. Error Handling:

    • Review and sanitize error messages to prevent sensitive information disclosure.
    • Log detailed error information securely and provide generic error messages to end-users.
    • Ensure the custom_msg parameter cannot be exploited for injection attacks.
  3. JSON Deserialization:

    • Validate all JSON input using a schema validation library like jsonschema.
    • Add tests to ensure that invalid or malicious JSON payloads are rejected.
  4. Code Hygiene:

    • Confirm that the removal of unused imports does not impact functionality.
    • Add comments or documentation to clarify the purpose of remaining imports.

Final Recommendation

Do not merge this pull request until the critical dependency confusion risks are addressed and mitigated. Additionally, the high-risk error handling concerns should be resolved to prevent potential information disclosure.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

🤖 AI Agent: test-generator — `packages/agent-compliance/src/agent_compliance/cli/main.py`

🧪 Test Coverage Analysis

packages/agent-compliance/src/agent_compliance/cli/main.py

  • Existing coverage:

    • The error handling function handle_error appears to be covered by tests that validate its behavior for known exceptions (IOError, ValueError, KeyError, PermissionError, FileNotFoundError) and unknown exceptions.
    • Tests likely verify the correct output format (JSON or plain text) based on the output_json flag.
  • Missing coverage:

    • Edge cases for custom_msg parameter, such as empty strings or special characters.
    • Behavior when output_json is True and custom_msg is provided.
    • Handling of unexpected exception types (e.g., custom exceptions or non-standard Python exceptions).
    • Validation of the type field in the JSON output for unknown exceptions.
  • 💡 Suggested test cases:

    1. test_handle_error_with_custom_msg — Verify that custom_msg overrides default error messages and handles edge cases like empty strings, special characters, or very long messages.
    2. test_handle_error_unknown_exception_json_output — Test the JSON output when an unknown exception occurs, ensuring the type field is set to InternalError.
    3. test_handle_error_known_exception_json_output — Test the JSON output for known exceptions, ensuring the type field is set to ValidationError.
    4. test_handle_error_non_standard_exception — Validate behavior when a non-standard Python exception is passed to the function.

packages/agent-compliance/src/agent_compliance/supply_chain.py

  • Existing coverage:

    • The file appears to define data structures (dataclass) and imports modules for supply chain validation. If tests exist for supply chain validation, they likely cover basic functionality, such as parsing supply chain data and validating inputs.
  • Missing coverage:

    • Edge cases for malformed supply chain data (e.g., missing fields, incorrect data types, or oversized payloads).
    • Validation of datetime handling, including edge cases like leap years, time zone conversions, and invalid date formats.
    • Behavior of SequenceMatcher in cases of partial matches or edge cases (e.g., empty strings, very large strings, or strings with special characters).
  • 💡 Suggested test cases:

    1. test_supply_chain_malformed_data — Test behavior when supply chain data is missing required fields or contains invalid data types.
    2. test_supply_chain_datetime_edge_cases — Validate handling of edge cases for datetime fields, such as leap years, daylight saving time transitions, and invalid date formats.
    3. test_sequence_matcher_edge_cases — Test SequenceMatcher behavior with edge cases like empty strings, very large strings, or strings containing special characters.
    4. test_supply_chain_large_payload — Verify the system's behavior when processing oversized supply chain data.

General Observations

  • The changes in this PR primarily address linting issues and dependency allowlists, which do not directly impact functional behavior. However, the modified files (main.py and supply_chain.py) contain logic that could benefit from additional edge case testing.
  • Ensure that tests for these files are located in the tests/agent_compliance/cli/test_main.py and tests/agent_compliance/test_supply_chain.py directories, respectively. If these test files do not exist, they should be created to improve coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR (< 50 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant