Solana: Yarn/Npm Package Vulnerabilities When Initializing a New Enchor Project
Relatively new to Anchor/Solana.
I have successfully set up my Anchor/Solana development environment, and have been able to build and run the newly created projects (with anchor init NAME) without any issues.
However, one thing that caught my attention was that I noticed some potential vulnerabilities when initializing a new Enchor project. As a Solana developer, it is important to be aware of these potential issues to ensure the security and reliability of your Enchor setup.
Here are some Yarn/Npm package vulnerabilities that I found when setting up a new Enchor project:
- Overly permissive Yarn Link Policy: By default, Yarn allows you to link a single repository between projects using Yarn Link. This can cause problems if you share dependencies across multiple projects.
- Lack of Security Audits: As the Solana ecosystem continues to grow, so does the number of vulnerabilities discovered in open source libraries and packages used by Anchor. Regular security audits and vulnerability scans can help identify potential issues before they become problems.
- Insufficient Yarn Lock Management: The Yarn lock file is critical to ensuring that dependencies are up-to-date and consistent across projects. Without proper management, your projects can end up with duplicate or outdated dependencies.
To prevent these vulnerabilities when initializing a new Anchor project, I recommend the following best practices.
1. Update Yarn to the latest version
Make sure you are using the latest version of Yarn by updating it using the ‘yarn outdated’ option, and then updating it to the latest version using ‘yarn install’.
yarn-deprecated --format=full | yarn-upgrade -g
2. Use a yarn link configuration file
Create a new file in the root of your project (e.g. .yarn-link-config.yaml) with the following content:
package: anchor-sdk
url:
This allows you to specify an external repository for shared dependencies between projects.
3. Configurenpm’ as a fallback
If you are concerned about Yarn’s permissiveness policy, consider configuring `npm’ as a fallback for specific packages or libraries that require it. This ensures that your project is still compatible with older versions of those dependencies.

Install Anchor SDK via npm (as a fallback)npm install anchor-sdk@latest --save-dev
Update 'yarn.lock' file to include npm insteadYarn Configuration Lock File yarn.lock
4. Perform regular security audits and vulnerability scans
Schedule regular security audits and vulnerability scans for your projects using tools like SonarQube, OWASP ZAP, or your preferred solution.
By following these best practices, you can significantly reduce the risk of Yarn/Npm package vulnerabilities when initializing a new Anchor project. Don’t forget to stay up to date with the latest developments in the Solana ecosystem to ensure the continued security and reliability of your Anchor setup.
