Skip to content

Add support for SECRET_TYPE_FILTER environment variable to filter secret scanning alerts #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 13, 2025

This PR adds support for filtering secret scanning alerts by specific secret types using a new SECRET_TYPE_FILTER environment variable, as requested in the issue.

Changes Made

  • Added SECRET_TYPE_FILTER environment variable support in main.py
  • Updated all secret scanning functions to accept an optional secret_type_filter parameter:
    • get_repo_ss_alerts()
    • get_org_ss_alerts()
    • get_enterprise_ss_alerts()
  • Enhanced URL construction to include the secret_type parameter when filtering is requested
  • Updated documentation in README.md to describe the new environment variable

Usage

Set the SECRET_TYPE_FILTER environment variable with a comma-separated list of secret types:

export SECRET_TYPE_FILTER="password,api_key,oauth_token"

This will filter secret scanning alerts to only include the specified secret types, matching the GitHub API's secret_type parameter behavior.

Example

The implementation supports the exact filtering pattern mentioned in the issue:

SECRET_TYPE_FILTER="password,http_basic_authentication_header,http_bearer_authentication_header,mongodb_connection_string,mysql_connection_string,openssh_private_key,pgp_private_key,postgres_connection_string,rsa_private_key"

Backward Compatibility

  • When SECRET_TYPE_FILTER is not set, the behavior remains unchanged (all secret types included)
  • Existing functionality and API signatures are preserved
  • No breaking changes to current usage patterns

Fixes #76.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Add support for generic/ai secrets Add support for SECRET_TYPE_FILTER environment variable to filter secret scanning alerts Jun 13, 2025
@Copilot Copilot AI requested a review from felickz June 13, 2025 20:49
Copilot finished work on behalf of felickz June 13, 2025 20:49
Copy link

@felickz felickz left a comment

Choose a reason for hiding this comment

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

Do not make this an input optional, just do it by default.

Instead of modifying the single query for secrets, this will require us to make two api calls.

The first query should remain as is, that will return all the default secret types (this excluedes the list the generic ones).

Then we need to make a second query with the applied filters (just hardcode this list as there is no better way).

Combine both results, there should not be duplicates CURRENTLY for this - there might be scenario in the future where the call without any filters actually does return the secret types for generics. Therefore create a combined (deduped list). If you can easilly detect duplicates, write a warning to the GitHub action output that says to notify the repo owners via an issue to report this duplicate behavior (this means we need to undo this change).

Thanks!

Copy link
Author

Copilot AI commented Jun 13, 2025

Do not make this an input optional, just do it by default.

Instead of modifying the single query for secrets, this will require us to make two api calls.
...

I've redesigned the implementation per your feedback in commit 14c7226:

  • Removed the optional SECRET_TYPE_FILTER environment variable
  • Modified all secret scanning functions to always make two API calls by default:
    1. First call: Regular query without filters (returns default secret types)
    2. Second call: Query with hardcoded generic secret types list
  • Combined results with deduplication logic
  • Added GitHub Actions warning output when duplicates are detected

The hardcoded generic secret types list includes: password, http_basic_authentication_header, http_bearer_authentication_header, mongodb_connection_string, mysql_connection_string, openssh_private_key, pgp_private_key, postgres_connection_string, rsa_private_key

Copilot finished work on behalf of felickz June 13, 2025 21:11
Copy link

@felickz felickz left a comment

Choose a reason for hiding this comment

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

LGTM - on a repo level test (todo test org/ent)

before ... no CSV when a repo only contained "generic" secrets and 0 "default"

after -
image

A different repo with both Default + Generic secrets detected - lists are combined:
image

@felickz felickz marked this pull request as ready for review June 22, 2025 16:15
@felickz felickz requested a review from aegilops as a code owner June 22, 2025 16:15
# Warn if duplicates were found
if duplicates_found:
print(
f"::warning::Duplicate secret scanning alerts detected in {repo_name}. Please report this behavior via an issue to the repository owners as the API behavior may have changed."
Copy link

Choose a reason for hiding this comment

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

Future proofing this fix in case the generic secrets are eventually returned via the normal API response without any explicit filtering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for generic/ai secrets
2 participants