T08 · Insecure Dependencies
- Location
database.md:53- Finding
Unpinned Package Retrieval and Execution Through npx
- Content
View full analysis
Vulnerability Details
File Location:
database.md, lines 53–57
Vulnerability Type: Unpinned third-party package execution
Risk Level: Mediumbash # Generate migration from entity changes npx typeorm migration:generate -d src/data-source.ts src/migrations/AddUserTable # Run migrations npx typeorm migration:run -d src/data-source.tsTechnical Analysis
The documentation instructs users to invoke TypeORM through
npxwithout specifying a reviewed version or requiring an existing project-local installation. If the executable is unavailable locally,npxmay retrieve and execute a package from the configured package registry.This behavior crosses a package-installation boundary at execution time. The effective code can differ from what was reviewed due to package updates, registry compromise, dependency confusion, or registry configuration changes. The migration command may also run with access to database configuration and application environment variables.
Attack Path
- A user follows the documented migration command.
- The expected TypeORM executable is absent from the local project dependencies.
npxresolves and downloads a package from the configured registry.- A compromised, substituted, or unexpectedly changed package executes under the user's account.
- Malicious package or lifecycle code reads accessible files, environment variables, or database credentials.
- Because the command is intended to run migrations, malicious code may connect to and modify the configured database.
Impact Assessment
Successful exploitation could execute arbitrary code with the privileges of the user running
npx. Accessible scope may include the project workspace, user-readable files, environment variables, package-registry credentials, and database credentials. If production database configuration is present, an attacker may be able to read, alter, or delete application data. The commands do not directly grant elevated oper ...[truncated 112 chars]- Remediation
View remediation
Remediation Suggestions
- Add a reviewed, explicitly pinned TypeORM version to the project's development dependencies.
- Commit and verify the package lockfile to ensure reproducible dependency resolution.
- Expose migration operations through package scripts that invoke the locked project-local binary.
- Where supported, use
npx --no-install typeorm ...so execution fails instead of downloading an absent package. - Use a trusted registry and enforce lockfile integrity in CI.
- Run migration generation and execution under a least-privileged account.
- Use database credentials limited to the permissions required for the migration environment.
- Review generated migrations before applying them, and never apply unreviewed migrations directly to production.
- A hardened example is:
json { "devDependencies": { "typeorm": "REVIEWED_PINNED_VERSION" }, "scripts": { "migration:generate": "typeorm migration:generate -d src/data-source.ts src/migrations/AddUserTable", "migration:run": "typeorm migration:run -d src/data-source.ts" } }
