composer.json and composer.lock files. However, you’ll get the best results if you have a lockfile with pinned dependencies.
Recommended Steps
-
Install Dependencies with Composer
Run one of these commands to generate acomposer.lockfile: -
Commit the Lockfile
Always commitcomposer.lockto your repository. This ensures that the entire team, and CybeDefend, see the exact dependency versions. -
Keep Your Lockfile Updated
When you want to update dependencies, usecomposer updateorcomposer requireand commit the updated lockfile.
Why You Should Use Lockfiles
Using a lockfile is critical for secure and predictable builds. A lockfile contains a fixed version and a hash for each dependency and sub-dependency in your project.- Supply Chain Protection
Lockfiles prevent malicious package injections. This is crucial as supply chain attacks are rising. - Predictable Builds
Everyone uses the exact same package versions, avoiding “it works on my machine” inconsistencies. - Performance Gains
With dependency versions locked, build tools skip the usual resolution step, making builds faster.
Lockfiles are never edited manually. They’re generated and updated by your package manager and committed to your repository, ensuring consistent environments for all teammates.
Troubleshooting Lockfile Generation
If you encounter issues generating a lockfile, try these approaches:While CybeDefend can scan projects with only a
composer.json file, we strongly recommend generating and committing the composer.lock file for more accurate vulnerability detection.Supported Files for PHP/Composer
| File Examples |
|---|
composer.json, composer.lock |