getsops / getsops/sops

creation_rules path_regex not matched against forward-slash paths on Windows

Open Beginner friendly
#2,237 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
23.1k
Forks
1.1k
Avg merge
1d 11h
Merged PRs (30d)
9

Description

Summary

On Windows, creation_rules[].path_regex is matched against the raw native-separator relative path (containing \), so regexes written with / — the natural style for cross-platform .sops.yaml shared between Windows/macOS/Linux devs — silently fail to match.

Reproduction

.sops.yaml:

creation_rules:
  - path_regex: secrets/.*\.env$
    age: age1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

On Windows:

sops -e secrets\prod.env
# Error: config file not found, or has no creation rules, and no keys provided through command line

Same command on macOS/Linux against secrets/prod.env works.

Root cause

config/config.go (v3.12.2):

  • Line 582 (configPathForFile) strips the config-dir prefix using filepath.Separator, so on Windows the remainder keeps \ separators.
  • Line 595 runs reg.MatchString(filePath) against that raw native-separator string.
  • Same pattern at line 522 for destination rules.

There is no filepath.ToSlash / strings.ReplaceAll(path, "\\", "/") before the regex match. Consequence: any path_regex using / as a separator (which is what every doc example and every cross-platform config uses) fails to match on Windows.

Users can work around it with [/\\], but that's non-obvious and pollutes shared .sops.yaml files.

Suggested fix

Normalize to forward slashes before matching, so the regex language stays platform-agnostic:

filePath = filepath.ToSlash(filePath)
if reg.MatchString(filePath) { ... }

Applied at both call sites (config.go:522 and config.go:595).

This is a one-line semantics change but strictly widens what matches on Windows — regexes written with [/\\] still match, regexes written with / start matching. No breakage for existing Linux/macOS users.

Environment

  • sops v3.12.2
  • Windows 11
  • PowerShell 7 and Git Bash both reproduce

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in config/config.go at the destination-rule matching around line 522 and configPathForFile around line 582, especially the regex match around line 595. Check how relative paths are normalized before both matches; done means slash-based path_regex rules match Windows paths while existing platform-specific patterns continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli, security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.