You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(cli): init command reading package.json from two folders up - #11789
Below is a summary of compliance checks for this PR:
Security Compliance
⚪
Path traversal risk
Description: Path traversal vulnerability: __dirname combined with relative path '../package.json' can be manipulated to access files outside intended directory, potentially exposing sensitive system files or configuration data. InitCommand.ts [682-682]
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful degradation
Status: Missing error handling: The dynamic file read operation at line 682 lacks error handling for cases where the package.json file might not exist or be malformed.
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent vulnerabilities
Status: Path traversal vulnerability: The file path constructed using __dirname at line 682 is not validated and could potentially be manipulated to access files outside the intended directory.
Why: The suggestion correctly identifies a critical path resolution bug where __dirname in the compiled code would point to the wrong location, causing the command to fail at runtime.
Correct the file path for package.json to account for the compiled output directory structure, preventing a runtime error when the init command is executed.
Why: The suggestion correctly identifies a critical runtime bug where the path to package.json would be incorrect after compilation, causing the init command to fail.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Description of change
When package is built or when we run tests, the
package.jsonis one level closer toInitCommand...It's a backport of part of the fix from #11787
Pull-Request Checklist
masterbranchFixes #00000PR Type
Bug fix, Enhancement
Description
Remove hardcoded package.json import, read dynamically at runtime
Make appendPackageJson async to support file reading operations
Update TypeScript compiler targets from ES2021 to ES2022/ES2023
Fix package.json path resolution for built and test environments
Diagram Walkthrough
File Walkthrough
InitCommand.ts
Dynamic package.json loading and TypeScript target updatessrc/commands/InitCommand.ts
package.jsonimport statement from top of fileappendPackageJsonmethod to async and added dynamic filereading using
CommandUtils.readFilegetTsConfigTemplatefrom ES2021to ES2022/ES2023
appendPackageJsonto handle asyncoperation