Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 25, 2025

This PR adds support for the Makefile variable pattern $(VARIABLE) in the @secretlint/secretlint-rule-database-connection-string rule to improve compatibility with Make-based projects.

Problem

The database-connection-string rule was flagging legitimate Makefile variables as secrets. For example, this common Makefile pattern would trigger false positives:

DB_URL = postgres://$(PGUSER):$(PGPASSWORD)@$(PGHOST)/$(PGDATABASE)

The isVariableLikeString function only supported these variable patterns:

  • ${var} - shell/bash variables
  • {{var}} - template variables like handlebars
  • {var} - generic template variables
  • %VAR% - Windows environment variables
  • $VAR - simple shell variables

Solution

Added the regex pattern /\$\([^)]{1,50}\)/ to the variablePatterns array in isVariableLikeString function to recognize Makefile variable syntax $(VAR).

The pattern:

  • Matches $( at the start
  • Captures 1-50 characters that are not )
  • Matches ) at the end
  • Maintains the same length limits as other patterns to prevent ReDoS attacks

Testing

Added comprehensive test cases showing that database connection strings with Makefile variables are properly ignored while real credentials are still detected:

# These are now properly ignored (no false positives)
DB_URL = postgres://$(PGUSER):$(PGPASSWORD)@$(PGHOST)/$(PGDATABASE)
MYSQL_URL = mysql://$(DB_USER):$(DB_PASS)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)

# These are still detected as secrets (functionality preserved)
REAL_DB = postgres://admin:myRealPassword123@localhost:5432/production

All existing tests continue to pass, ensuring no regression in functionality.

Fixes #1190.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI assigned Copilot and azu Aug 25, 2025
Copy link
Contributor Author

Copilot AI commented Aug 25, 2025

@azu 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

…nection-string rule

Co-authored-by: azu <19714+azu@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] How about to support Makefile variable pattern $(VARIABLE) in database-connection-string rule Add support for Makefile variable pattern $(VARIABLE) in database-connection-string rule Aug 25, 2025
@Copilot Copilot AI requested a review from azu August 25, 2025 14:10
Copilot finished work on behalf of azu August 25, 2025 14:10
@azu azu marked this pull request as ready for review August 25, 2025 14:13
@azu azu added the Type: Bug Bug or Bug fixes label Aug 25, 2025
@azu azu enabled auto-merge (squash) August 25, 2025 14:14
@azu azu merged commit e4cc4f2 into master Aug 25, 2025
24 of 40 checks passed
@azu azu deleted the copilot/fix-1190 branch August 25, 2025 14:20
This was referenced Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug or Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How about to support Makefile variable pattern $(VARIABLE) in database-connection-string rule
2 participants