Skip to content

feat(security): add dependency confusion pre-commit hook + weekly audit CI#350

Merged
imran-siddique merged 14 commits intomicrosoft:mainfrom
imran-siddique:main
Mar 23, 2026
Merged

feat(security): add dependency confusion pre-commit hook + weekly audit CI#350
imran-siddique merged 14 commits intomicrosoft:mainfrom
imran-siddique:main

Conversation

@imran-siddique
Copy link
Copy Markdown
Member

Proactive security tooling from audit recommendations:

  • **\scripts/check_dependency_confusion.py**: Pre-commit hook that scans for \pip install\ commands referencing unregistered PyPI packages. Maintains allowlist of known packages.
  • **\weekly-security-audit.yml**: Weekly CI job running dependency confusion scan, security skills scan, and weak crypto check. Reports uploaded as 90-day artifacts.

imran-siddique and others added 14 commits March 20, 2026 10:56
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add EU AI Act, Colorado AI Act, and GPAI obligations timeline with
AGT coverage mapping. Reference Microsoft Purview DSPM for AI as
complementary data governance layer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The Scorecard API rejects workflows with write permissions at the
workflow level. id-token: write and security-events: write must be
scoped to the job level only. Restores permissions: read-all at
workflow level while keeping job-level write permissions intact.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ft#324)

Add Google-style docstrings with Args, Returns, Raises, Attributes,
and Example sections to MCPMessageType, MCPAdapter, and MCPServer
classes. Also enhances docstrings for key methods including
handle_message, _handle_tools_call, _handle_resources_read, and
_map_tool_to_action.

Fixes microsoft#316
Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
…s (dependency confusion) (microsoft#325)

- Replace !pip install agent-os with !pip install -e ../.. in all 6 notebooks;
  agent-os is not on PyPI and installing it from PyPI is a dependency confusion vector
- Replace zendesk-sdk/freshdesk-sdk with zenpy/freshdesk (the real published SDKs)
  in customer-service/requirements.txt
- Remove hashlib-compat from healthcare-hipaa/requirements.txt; hashlib is stdlib
  and hashlib-compat is not a real PyPI package
…stall agent-os with agent-os-kernel

Replace all remaining instances of `pip install agent-os` (unregistered
on PyPI) with `pip install agent-os-kernel` (the actual package) across
docs, examples, TypeScript extensions, CLI source, tests, and SVG assets.

Also fixes `pip install emk` references to point to `agent-os-kernel[full]`
since emk is a submodule, not a standalone PyPI package.

Completes the fix started in PR microsoft#325 which only covered notebooks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Dify 65K→133K, AutoGen 42K→55K, CrewAI 28K→46K, Semantic Kernel
24K→27K, LangGraph 24K→27K, Haystack 22K→24K, Agent Framework
7.6K→8K. Added star counts for OpenAI Agents SDK (20K) and
Google ADK (18K). Sorted by stars descending.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…it CI

- scripts/check_dependency_confusion.py: Pre-commit hook that scans for
  pip install commands referencing unregistered PyPI packages. Maintains
  an allowlist of known registered packages.
- .github/workflows/weekly-security-audit.yml: Weekly CI job running
  dependency confusion scan, security skills scan, and weak crypto check.
  Uploads reports as artifacts with 90-day retention.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@imran-siddique imran-siddique merged commit 25812e5 into microsoft:main Mar 23, 2026
@github-actions github-actions bot added ci/cd CI/CD and workflows size/L Large PR (< 500 lines) labels Mar 23, 2026
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 introduces a pre-commit hook and a weekly CI job to detect and prevent dependency confusion attacks, weak cryptography usage, and other security issues. The changes are a step in the right direction for improving the security posture of the repository. However, there are some areas that require attention to ensure correctness, security, and maintainability.


🔴 CRITICAL

  1. Potential False Negatives in Dependency Confusion Detection:

    • The extract_package_names function does not handle all possible cases of pip install syntax. For example:
      • It does not account for cases where package names are specified with environment variables (e.g., pip install $PACKAGE_NAME).
      • It does not handle cases where package names are specified in a requirements file with complex version specifiers (e.g., package[extra]>=1.0,<2.0).
    • Action: Use a more robust parser for pip install commands, such as leveraging pip's own internal parsing logic or a library like packaging.
  2. Weak Cryptography Check:

    • The weak cryptography check only looks for hashlib.md5 and hashlib.sha1 but does not account for other weak cryptographic algorithms or libraries (e.g., hmac.new(..., digestmod=hashlib.md5) or custom implementations of MD5/SHA1).
    • Action: Expand the weak cryptography check to include other weak algorithms and patterns. Consider using a static analysis tool like bandit for this purpose.
  3. Pickle Usage Check:

    • The pickle usage check only looks for pickle.load but does not account for other unsafe methods like pickle.loads or alternative libraries like cPickle.
    • Action: Expand the check to include all unsafe deserialization methods and libraries.
  4. Lack of Validation for REGISTERED_PACKAGES:

    • The REGISTERED_PACKAGES list is manually maintained, which introduces the risk of human error or outdated entries.
    • Action: Implement an automated mechanism to periodically validate the REGISTERED_PACKAGES list against the PyPI registry to ensure it remains up-to-date.

🟡 WARNING

  1. Backward Compatibility:

    • The addition of the pre-commit hook could potentially disrupt existing workflows if developers are not aware of its presence or if it blocks commits due to false positives.
    • Action: Clearly document the pre-commit hook in the repository's CONTRIBUTING.md file and provide instructions for bypassing the hook if necessary (e.g., git commit --no-verify).
  2. Potential Breaking Changes in CI:

    • The weekly security audit CI job could fail due to false positives in the dependency confusion or security scans, which might block other workflows or create noise.
    • Action: Ensure that the CI job does not block other workflows and that false positives are minimized. Consider running the job in a separate pipeline or as an informational job.

💡 SUGGESTIONS

  1. Improve Logging and Error Reporting:

    • The check_dependency_confusion.py script could benefit from more detailed logging, such as indicating which files are being scanned and providing context for findings.
    • Action: Add logging statements to indicate progress and provide more context for findings.
  2. Test Coverage:

    • There is no evidence of test coverage for the check_dependency_confusion.py script or the new CI jobs.
    • Action: Add unit tests for the check_dependency_confusion.py script and integration tests for the CI workflows to ensure they function as expected.
  3. Use of continue-on-error:

    • The security-skills-scan job uses continue-on-error: true, which could lead to missed issues if the job fails silently.
    • Action: Consider removing continue-on-error and instead handle errors explicitly within the script to ensure that issues are surfaced appropriately.
  4. Dependency Management:

    • The pip install commands in the CI workflows do not pin dependency versions, which could lead to non-deterministic behavior.
    • Action: Pin the versions of all dependencies in the CI workflows to ensure reproducibility.
  5. Documentation:

    • The new scripts and workflows are not documented in the repository.
    • Action: Update the repository's documentation to include details about the new pre-commit hook and weekly security audit CI job.
  6. Security Skills Scan:

    • The security_scan.py script is not included in the diff, so its implementation cannot be reviewed. However, it is critical to ensure that it adheres to best practices for security scanning.
    • Action: Provide the implementation of security_scan.py for review.
  7. Performance Optimization:

    • The check_dependency_confusion.py script scans all files matching certain extensions, which could be inefficient for large repositories.
    • Action: Optimize the file scanning process by limiting it to relevant directories or using a more efficient file traversal method.

Final Recommendation

  • Address the critical issues to ensure the correctness and security of the changes.
  • Consider the warnings to avoid potential disruptions to existing workflows.
  • Implement the suggestions to improve the maintainability, performance, and usability of the new features.

Once the critical issues are resolved and the warnings are addressed, this pull request can be approved.

@github-actions
Copy link
Copy Markdown

🤖 AI Agent: security-scanner — Security Review of PR: feat(security): add dependency confusion pre-commit hook + weekly audit CI

Security Review of PR: feat(security): add dependency confusion pre-commit hook + weekly audit CI


Findings:

1. Dependency Confusion Detection Logic

  • Severity: 🔵 LOW
  • Issue: The check_dependency_confusion.py script relies on a hardcoded list of REGISTERED_PACKAGES to identify valid PyPI packages. This approach is prone to becoming outdated as new dependencies are added to the project or as package names change.
  • Attack Vector: If a developer forgets to update the REGISTERED_PACKAGES list when adding a new dependency, the script may flag legitimate packages as unregistered. Conversely, if a malicious actor introduces a typo-squatted package name that closely resembles a legitimate package but is not in the list, it may bypass detection.
  • Recommendation: Instead of relying solely on a hardcoded list, integrate a real-time check against the PyPI registry using the PyPI JSON API (e.g., https://pypi.org/pypi/<package-name>/json). This would ensure that the script always checks against the latest list of registered packages. The hardcoded list can still be used as a fallback for private/internal packages.

2. Pre-commit Hook Installation Instructions

  • Severity: 🔵 LOW
  • Issue: The script includes instructions for manual installation as a pre-commit hook, but this process is error-prone and may lead to inconsistent usage across developers.
  • Attack Vector: If developers fail to install the pre-commit hook correctly, the dependency confusion check may not be consistently applied, leaving the repository vulnerable to dependency confusion attacks.
  • Recommendation: Instead of relying on manual installation, integrate the script with a pre-commit configuration file (e.g., .pre-commit-config.yaml). This ensures that the hook is automatically installed and executed when developers clone the repository and run pre-commit install.

3. Potential Credential Exposure in Logs

  • Severity: 🟠 HIGH
  • Issue: The check_dependency_confusion.py script captures and prints the output of the git diff command, which could potentially include sensitive information (e.g., credentials in modified files).
  • Attack Vector: If sensitive information is accidentally committed and then flagged by the script, it could be exposed in CI logs or local developer environments.
  • Recommendation: Sanitize the output of the git diff command to ensure that sensitive information is not inadvertently logged. For example, redact lines containing patterns like password=, secret=, or key=.

4. Race Condition in Dependency Confusion Check

  • Severity: 🟠 HIGH
  • Issue: The check_dependency_confusion.py script relies on the output of git diff to identify staged files. However, there is a potential Time-of-Check-to-Time-of-Use (TOCTOU) race condition if files are modified between the time they are staged and the time the script runs.
  • Attack Vector: An attacker could modify a file after staging it but before the script runs, bypassing the dependency confusion check.
  • Recommendation: Use git diff --cached to ensure that the script checks the exact content of the staged files, rather than the current working directory. Additionally, consider hashing the content of the staged files and verifying the hashes before processing them.

5. Lack of Comprehensive Dependency Scanning

  • Severity: 🟡 MEDIUM
  • Issue: The check_dependency_confusion.py script only scans for pip install commands in specific file types (.md, .py, .ts, etc.). This approach may miss dependencies declared in other formats (e.g., requirements.txt, pyproject.toml, setup.py, or package.json).
  • Attack Vector: If dependencies are declared in an unscanned file or format, they may bypass the dependency confusion check.
  • Recommendation: Extend the script to parse and validate dependencies from common package management files (e.g., requirements.txt, pyproject.toml, setup.py, package.json). For example, use pip or poetry to parse Python dependencies and npm for JavaScript dependencies.

6. Weak Cryptography Check

  • Severity: 🔵 LOW
  • Issue: The weak cryptography check only scans for hashlib.md5 and hashlib.sha1 in Python files. However, weak cryptographic algorithms may also be used in other contexts (e.g., JavaScript code or configuration files).
  • Attack Vector: If weak cryptographic algorithms are used in non-Python files, they may go undetected.
  • Recommendation: Extend the weak cryptography check to include other file types (e.g., .js, .ts, .yaml, .json) and search for common weak algorithms (e.g., MD5, SHA-1, DES, RC4).

7. Deserialization Check

  • Severity: 🟠 HIGH
  • Issue: The deserialization check only looks for pickle.load in Python files. However, unsafe deserialization can occur with other libraries (e.g., yaml.load without Loader=SafeLoader) or in other languages (e.g., JavaScript's eval or JSON.parse).
  • Attack Vector: An attacker could exploit unsafe deserialization in other contexts, bypassing the current check.
  • Recommendation: Extend the deserialization check to include other unsafe deserialization patterns (e.g., yaml.load, eval, exec, JSON.parse) and other file types (e.g., .js, .ts, .yaml).

8. Hardcoded Dependencies in CI

  • Severity: 🟡 MEDIUM
  • Issue: The CI workflow uses hardcoded versions of GitHub Actions (e.g., actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683) and Python dependencies (e.g., pyyaml). While pinning versions is good practice, these versions may become outdated over time.
  • Attack Vector: Using outdated dependencies or GitHub Actions could expose the pipeline to vulnerabilities in those dependencies.
  • Recommendation: Regularly review and update the pinned versions of dependencies and GitHub Actions. Consider using Dependabot or a similar tool to automate this process.

Summary of Findings:

Finding Severity Fix Recommendation
Dependency confusion detection logic 🔵 LOW Use PyPI JSON API for real-time validation of package names.
Pre-commit hook installation instructions 🔵 LOW Integrate with .pre-commit-config.yaml for automatic hook installation.
Credential exposure in logs 🟠 HIGH Sanitize git diff output to redact sensitive information.
Race condition in dependency check 🟠 HIGH Use git diff --cached and hash staged file content before processing.
Lack of comprehensive dependency scanning 🟡 MEDIUM Extend scanning to include requirements.txt, pyproject.toml, setup.py, etc.
Weak cryptography check 🔵 LOW Expand check to include weak algorithms in non-Python files.
Deserialization check 🟠 HIGH Extend check to include other unsafe deserialization patterns and file types.
Hardcoded dependencies in CI 🟡 MEDIUM Regularly review and update pinned versions; consider using Dependabot.

Overall Assessment:

This PR introduces valuable security measures to detect dependency confusion, weak cryptography, and unsafe deserialization. However, there are some areas for improvement to enhance the robustness of the checks and reduce the risk of bypasses or false negatives. Addressing the identified issues will significantly strengthen the security posture of the repository.

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

Labels

ci/cd CI/CD and workflows size/L Large PR (< 500 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants