Skip to content

🛡️ Sentinel: [HIGH] Fix sensitive data leakage and regex injection in publish flow#120

Open
calionauta wants to merge 1 commit into
mainfrom
sentinel/fix-publish-leak-and-regex-injection-14325187048638486411
Open

🛡️ Sentinel: [HIGH] Fix sensitive data leakage and regex injection in publish flow#120
calionauta wants to merge 1 commit into
mainfrom
sentinel/fix-publish-leak-and-regex-injection-14325187048638486411

Conversation

@calionauta

Copy link
Copy Markdown
Owner

🚨 Severity: HIGH
💡 Vulnerability:

  1. Sensitive data leakage: The hand-rolled exclusion logic in git_publish.py was brittle and failed to match many sensitive patterns (like sessions/, cache/, .env), potentially leaking personal data to public repositories.
  2. Regex newline injection: Skill name validation used the $ anchor, which in Python allows a trailing newline to pass. This could be exploited if these names are used in shell commands.

🎯 Impact:

  • Personal credentials, API keys, and session history could be accidentally published.
  • Potential argument injection or other malicious behavior via crafted skill names.

🔧 Fix:

  • Switched to fnmatch.filter for robust pattern matching in git_publish.py.
  • Changed $ to \Z in regex patterns for absolute end-of-string matching.

✅ Verification:

  • Added tests/test_publish_security_sentinel.py covering both vulnerabilities.
  • Verified with a reproduction script that sensitive files are no longer leaked.
  • All 571 tests passed.

PR created automatically by Jules for task 14325187048638486411 started by @calionauta

… publish flow

- Hardened `_ignore_func` in `git_publish.py` using `fnmatch.filter` to correctly exclude sensitive directories and files.
- Replaced vulnerable `$` anchor with `\Z` in `_is_valid_skill_name` regex across `local_source.py` and `external_source.py` to prevent newline injection.
- Added comprehensive security regression tests in `tests/test_publish_security_sentinel.py`.
- Updated sentinel journal with findings.

Co-authored-by: calionauta <1719651+calionauta@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request addresses security vulnerabilities by updating skill name validation regexes to use \Z instead of $ to prevent trailing newline bypasses, and refactoring the file exclusion logic in git_publish.py to use fnmatch.filter instead of manual string matching. It also adds a comprehensive test suite for these security measures. The review feedback correctly highlights that fnmatch.filter is case-sensitive on Unix-like filesystems, which could allow uppercase or mixed-case sensitive files (like .ENV or personal.PEM) to bypass the exclusion filter. To resolve this, the reviewer suggested implementing case-insensitive matching in the ignore function and adding corresponding test cases and assertions.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +35 to +38
ignored = set()
for pattern in patterns:
ignored.update(fnmatch.filter(names, pattern))
return list(ignored)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

security-high high

On case-sensitive filesystems (such as Linux, which is commonly used in production and CI/CD environments), fnmatch.filter performs case-sensitive matching. This means sensitive files with mixed-case or uppercase names/extensions (e.g., .ENV, personal.PEM, models.JSON) will bypass the exclusion filter and potentially be leaked to public repositories.\n\nTo ensure robust, case-insensitive exclusion across all platforms, we can map the lowercase names back to their original casing when filtering.

        ignored = set()\n        lower_to_orig = {name.lower(): name for name in names}\n        for pattern in patterns:\n            matched_lowers = fnmatch.filter(lower_to_orig.keys(), pattern.lower())\n            ignored.update(lower_to_orig[m] for m in matched_lowers)\n        return list(ignored)

Comment on lines +21 to +24
# Sensitive files
(src / ".env").write_text("API_KEY=123")
(src / "models.json").write_text("{}")
(src / "personal.pem").write_text("key")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To ensure the exclusion logic is robust against case-sensitivity issues on Unix-like filesystems, we should add test cases with mixed-case and uppercase sensitive filenames (e.g., .ENV, models.JSON, personal.PEM). This will verify that the case-insensitive matching works correctly.

Suggested change
# Sensitive files
(src / ".env").write_text("API_KEY=123")
(src / "models.json").write_text("{}")
(src / "personal.pem").write_text("key")
# Sensitive files (including mixed/uppercase to test case-insensitivity)\n (src / ".env").write_text("API_KEY=123")\n (src / ".ENV").write_text("API_KEY=123")\n (src / "models.json").write_text("{}")\n (src / "models.JSON").write_text("{}")\n (src / "personal.pem").write_text("key")\n (src / "personal.PEM").write_text("key")

Comment on lines +40 to +42
assert not (dest / ".env").exists()
assert not (dest / "models.json").exists()
assert not (dest / "personal.pem").exists()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Add assertions for the mixed-case and uppercase sensitive files to verify they are also successfully excluded.

            assert not (dest / ".env").exists()\n            assert not (dest / ".ENV").exists()\n            assert not (dest / "models.json").exists()\n            assert not (dest / "models.JSON").exists()\n            assert not (dest / "personal.pem").exists()\n            assert not (dest / "personal.PEM").exists()

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.

1 participant