Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 8993

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 28, 20242024-11-28T06:17:09+00:00 2024-11-28T06:17:09+00:00

Preventing Installing Composer Dependencies with Known Security Vulnerabilities

  • 60k

Introduction

A key piece of building modern-day web applications with PHP involves using packages and libraries built by other developers around the world.

As a result of this, it means there can be a lot of moving pieces that you don't always have control over. So it can be possible for you to install dependencies in your PHP projects that have known vulnerabilities. Whether the vulnerabilities be bugs that were accidentally introduced, or supply-chain attacks that were intentionally added.

To reduce the chance of introducing vulnerable dependencies into your projects, you can use tools such as “Roave Security Advisories” (roave/security-advisories).

So in this Quickfire article, we're going to discuss how you can use Roave Security Advisories to prevent you from installing Composer dependencies with known security vulnerabilities into your PHP projects.

What is Roave Security Advisories?

Security Advisories is a Composer package by Roave that stops you from being able to install other Composer dependencies that have known vulnerabilities.

It's really simple to start using (we'll take a look at that a bit further down).

The package doesn't really contain any actual PHP code, and instead is mainly just a composer.json file that causes conflicts in Composer when trying to install vulnerable dependencies.

There are other tools out there, such as Enlightn and Dependabot, that help you to detect dependencies in your project with security vulnerabilities. But I'd like to think of these types of tools more as being “reactive”. By that, I mean that they can alert you of vulnerable dependencies after you've installed them in your project. This can result in you introducing potential security holes into your applications without being aware at first. This is by no means a discredit to any of these types of tools though. Vulnerabilities are always being discovered in frameworks, packages, and libraries. So being able to detect them is a great way to stay on top of your project's security.

However, Security Advisories is a little bit different and can be treated as more of a “proactive” tool. By this, I mean that it actually stops you from being able to install dependencies with known vulnerabilities in the first place. But it can also be used as an auditing tool to “reactively” detect vulnerable dependencies already installed in your application.

It's worth remembering that the package will only prevent you from installing dependencies with known vulnerabilities. So this means it is still possible to install vulnerable packages if the vulnerabilities haven't yet been detected and documented.

How to Use Roave Security Advisories

To get started with using Security Advisories, you can add it as require-dev dependency in your project by running the following command in your project root:

composer require --dev roave/security-advisories:dev-latest 
Enter fullscreen mode Exit fullscreen mode

If you aren't currently using any dependencies that have known vulnerabilities, roave/security-advisories should now be successfully installed. However, if you do have any vulnerable packages, the installation will fail and show you which package is causing the issue.

Now, whenever you run composer require or composer update, if any of the packages that are being installed or updated have known vulnerabilities, Security Advisories will prevent the install and force Composer to throw an error.

As an example, let's imagine that we want to install a version of Laravel (8.22.1) that has a known vulnerability. If we were to run composer require laravel/framework:8.22.1, Composer would output the following in our terminal:

./composer.json has been updated  Running composer update roave/security-advisories Loading composer repositories with package information Updating dependencies Your requirements could not be resolved to an installable set of packages.    Problem 1     - laravel/framework is locked to version v8.22.1 and an update of this package was not requested.     - roave/security-advisories dev-latest conflicts with illuminate/database <6.20.26|>=7,<7.30.5|>=8,<8.40 (laravel/framework v8.22.1 replaces illuminate/database self.version).     - Root composer.json requires roave/security-advisories dev-latest -> satisfiable by roave/security-advisories[dev-latest].  Installation failed, reverting ./composer.json and ./composer.lock to their original content. 
Enter fullscreen mode Exit fullscreen mode

As you can see, Security Advisories prevented this version of laravel/framework from being installed.

It's important to remember that these checks are only run when running the composer require and composer update commands. So if you just run composer install and have a valid composer.lock file, it won't detect any vulnerabilities in your dependencies.

However, if you want to check your current dependencies for any vulnerabilities that may have been discovered since you last updated your dependencies, you can run the following command:

composer update --dry-run roave/security-advisories   
Enter fullscreen mode Exit fullscreen mode

This will perform a dry run of updating your dependencies but not actually make any changes to your vendor files.

Because of the nature of the package and how it works, there aren't any tagged versions of it. This means you'll need to keep using the dev-latest version so that each time you update the package, you'll get an updated list of vulnerable dependencies.

Conclusion

Hopefully, this post should have shown you how you can start using Roave Security Advisories in your PHP projects to prevent you from installing dependencies with known security vulnerabilities.

If you enjoyed reading this post, I'd love to hear about it. Likewise, if you have any feedback to improve the future ones, I'd also love to hear that too.

You might also be interested in checking out my 220+ page ebook “Battle Ready Laravel” which covers similar topics in more depth.

If you're interested in getting updated each time I publish a new post, feel free to sign up for my newsletter.

Keep on building awesome stuff! 🚀

laravelphpsecuritywebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.