Skip to content

[PM-34027] fix: use fileURLToPath for main module detection#168

Open
tecnologicachile wants to merge 2 commits intobitwarden:mainfrom
tecnologicachile:fix/main-module-check
Open

[PM-34027] fix: use fileURLToPath for main module detection#168
tecnologicachile wants to merge 2 commits intobitwarden:mainfrom
tecnologicachile:fix/main-module-check

Conversation

@tecnologicachile
Copy link
Copy Markdown

Summary

  • Replace the brittle process.argv[1].endsWith('index.js') main module check with process.argv[1] === fileURLToPath(import.meta.url)
  • Add import { fileURLToPath } from 'url' to support the new check
  • The previous check fails when the server is invoked via the npm binary wrapper (mcp-server-bitwarden), because process.argv[1] points to the symlink/wrapper script rather than index.js, so the server never starts

Test plan

  • npm run build compiles successfully
  • Run npx mcp-server-bitwarden and verify the server starts (previously it would silently exit)
  • Run node dist/index.js directly and verify it still starts correctly

Fixes #158

🤖 Generated with Claude Code

The previous check using endsWith('index.js') fails when the server
is invoked via the npm binary wrapper (mcp-server-bitwarden), because
process.argv[1] points to the symlink rather than index.js.

Fixes bitwarden#158

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tecnologicachile tecnologicachile requested a review from a team as a code owner March 24, 2026 02:22
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 24, 2026

CLA assistant check
All committers have signed the CLA.

@bitwarden-bot
Copy link
Copy Markdown

Thank you for your contribution! We've added this to our internal tracking system for review.
ID: PM-34027
Link: https://bitwarden.atlassian.net/browse/PM-34027

Details on our contribution process can be found here: https://contributing.bitwarden.com/contributing/pull-requests/community-pr-process.

@bitwarden-bot bitwarden-bot changed the title fix: use fileURLToPath for main module detection [PM-34027] fix: use fileURLToPath for main module detection Mar 24, 2026
The previous fix using fileURLToPath alone still fails when Node.js
invokes the script through the npm bin symlink, because process.argv[1]
points to the symlink path while import.meta.url resolves to the real
file. Using realpathSync ensures both paths resolve to the same target.

Fixes bitwarden#158

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@withinfocus withinfocus added ai-review-vnext Request a Claude code review using the vNext workflow and removed needs-qa labels Mar 25, 2026
Copy link
Copy Markdown
Contributor

@withinfocus withinfocus left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. We pin dependencies and you can remove your unrelated change.

Comment thread package.json
"prettier": "3.8.1",
"ts-jest": "29.4.6",
"typescript": "5.9.3",
"typescript": "^5.9.3",
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.

This can be reverted.

@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 51.92%. Comparing base (38762b7) to head (287a24d).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/index.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #168   +/-   ##
=======================================
  Coverage   51.92%   51.92%           
=======================================
  Files          12       12           
  Lines         909      909           
  Branches      197      197           
=======================================
  Hits          472      472           
  Misses        387      387           
  Partials       50       50           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown

Logo
Checkmarx One – Scan Summary & Detailsd0550273-286c-4802-8942-5952f193bcaf


New Issues (1) Checkmarx found the following issues in this Pull Request
# Severity Issue Source File / Package Checkmarx Insight
1 HIGH CVE-2026-33228 Npm-flatted-3.4.1
detailsRecommended version: 3.4.2
Description: The "parse()" function in flatted can use attacker-controlled string values from the parsed JSON as direct array index keys, without validating t...
Attack Vector: NETWORK
Attack Complexity: LOW
Vulnerable Package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review-vnext Request a Claude code review using the vNext workflow community-pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcp-server-bitwarden binary exits immediately due to process.argv[1] check failing

4 participants