Skip to content

fix(security): address CodeQL, OpenSSF Scorecard, and npm audit findings#12

Merged
mirowolff merged 10 commits intobitbonsai:mainfrom
hellvinz:main
Dec 8, 2025
Merged

fix(security): address CodeQL, OpenSSF Scorecard, and npm audit findings#12
mirowolff merged 10 commits intobitbonsai:mainfrom
hellvinz:main

Conversation

@hellvinz
Copy link
Copy Markdown
Contributor

@hellvinz hellvinz commented Dec 8, 2025

Summary

This PR addresses security vulnerabilities identified by CodeQL, OpenSSF Scorecard, Dependabot, and npm audit, plus adds comprehensive test coverage.

Changes

Dependency Vulnerabilities (Dependabot + npm audit)

  • Fixed vulnerabilities flagged by Dependabot alerts
  • Resolved all npm audit findings

TOCTOU Race Conditions (filesystem.ts)

  • Flagged by CodeQL as js/file-system-race
  • Remove check-then-act patterns (access() followed by readFile/unlink)
  • Handle ENOENT/EACCES errors directly from operations
  • Use atomic file operations where possible

Ref: https://cwe.mitre.org/data/definitions/367.html

Regex Injection in Glob Patterns (pathfilter.ts)

  • Flagged by CodeQL as js/incomplete-sanitization
  • Escape regex special characters before glob-to-regex conversion
  • Prevents patterns like backup.2024/** from being misinterpreted
  • Normalize backslashes for Windows compatibility

Ref: https://codeql.github.com/codeql-query-help/javascript/js-incomplete-sanitization/

OpenSSF Scorecard Findings

  • Use mkdtemp for unpredictable temp directories in tests
  • Added SECURITY.md with vulnerability reporting guidelines

Automated detection of security vulnerabilities in TypeScript code
(path traversal, injection, prototype pollution) to protect users'
personal vault data.

Uses security-extended queries and runs weekly to catch new CVEs.

Ref: https://docs.github.com/en/code-security/code-scanning/introduction-to-code-scanning/about-code-scanning-with-codeql
Prevent supply chain attacks through compromised dependencies by
validating lockfile integrity and running npm audit on every PR.

Lockfile validation detects dependency confusion attacks where
package-lock.json diverges from declared dependencies.

Refs:
- https://docs.npmjs.com/cli/v10/commands/npm-audit
- https://blog.npmjs.org/post/626173315965468672/npm-v7-series-why-keep-package-lockjson
Ensure known vulnerabilities (CVEs) in dependencies are patched
promptly without manual tracking.

Major updates stay as separate PRs for careful review of breaking changes.

Ref: https://docs.github.com/en/code-security/dependabot/dependabot-security-updates/about-dependabot-security-updates
Allow users to verify that npm packages were built from this exact
GitHub repository and commit, not from a compromised machine.

Verification: npm audit signatures

Requires NPM_TOKEN secret in repository settings.

Ref: https://docs.npmjs.com/generating-provenance-statements
Automated evaluation of security practices (branch protection,
dependency updates, signed releases, etc.) with results visible
in GitHub Security tab.

Helps identify gaps in project security hygiene.

Ref: https://securityscorecards.dev/
Upgrade vitest 1.6.1 → 4.0.15 to resolve transitive vite/esbuild
vulnerabilities. Sync lockfile with package.json 0.7.0.

Refs:
- GHSA-w48q-cv73-mx4w
- GHSA-mh29-5h37-fv8m
- GHSA-67mh-4wv8-2f99
Remove check-then-act patterns that were flagged by CodeQL as
js/file-system-race vulnerabilities.

Instead of access() followed by readFile/unlink/etc, handle ENOENT
errors directly from the operation. Use writeFile with 'wx' flag
for atomic "create if not exists" in moveNote().

Ref: https://cwe.mitre.org/data/definitions/367.html
The glob-to-regex conversion wasn't escaping special regex characters,
allowing patterns with characters like . + $ etc to be misinterpreted.

Also normalizes backslashes in patterns for Windows compatibility.

Ref: https://codeql.github.com/codeql-query-help/javascript/js-incomplete-sanitization/
Predictable paths in /tmp are vulnerable to symlink attacks.
mkdtemp creates directories with random suffixes, preventing
local attackers from pre-creating malicious symlinks.

Ref: https://codeql.github.com/codeql-query-help/javascript/js-insecure-temporary-file/
Define responsible disclosure process, security scope, and response
timelines for vulnerability reports.

Documents implemented security controls and clarifies what's in/out
of scope for this project vs upstream (MCP protocol, Obsidian).

Ref: https://docs.github.com/en/code-security/getting-started/adding-a-security-policy-to-your-repository
@mirowolff mirowolff merged commit 1dd71b4 into bitbonsai:main Dec 8, 2025
mirowolff added a commit that referenced this pull request Dec 8, 2025
Version bump accounts for PR #12 security fixes (0.7.1) and website updates.

Add comprehensive integration test suite covering:
- End-to-end service layer workflows
- Special characters in paths (parentheses, brackets, unicode, emoji)
- Regex special chars in content
- Security: path traversal and blocked directories
- Multi-step workflows (search → read → update)
- Performance regression tests

All 102 tests passing.
@bitbonsai
Copy link
Copy Markdown
Owner

@hellvinz Really appreciate this PR! Took some time to go through the changes properly - the TOCTOU fixes and regex
escaping are spot on. Love that you included the full security tooling setup (CodeQL, Scorecard, etc.) and
comprehensive test coverage.

After merging I added some integration tests to make sure everything plays nicely with the existing workflows. All 102
tests passing, no issues found.

Merged as v0.7.2. Thanks for taking the time to strengthen the security here! 🙏

@hellvinz
Copy link
Copy Markdown
Contributor Author

hellvinz commented Dec 8, 2025

@hellvinz Really appreciate this PR! Took some time to go through the changes properly - the TOCTOU fixes and regex escaping are spot on. Love that you included the full security tooling setup (CodeQL, Scorecard, etc.) and comprehensive test coverage.

After merging I added some integration tests to make sure everything plays nicely with the existing workflows. All 102 tests passing, no issues found.

Merged as v0.7.2. Thanks for taking the time to strengthen the security here! 🙏

No problem! Thank you for writing this MCP server. I wanted to use it, but I wanted to be sure about my data too.

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.

3 participants