Git Product home page Git Product logo

Comments (4)

Ocramius avatar Ocramius commented on May 28, 2024 1

from security-advisories.

Ocramius avatar Ocramius commented on May 28, 2024

web-APIs and RSS feeds where available

Those feeds are designed for human consumption, not for machine consumption.

from security-advisories.

phptek avatar phptek commented on May 28, 2024

In a few lines of Python, I can parse that feed and compare with a project's composer.lock.

#!/usr/bin/python
#
# Russell Michell 2018 <[email protected]>
#
# What is this?
#
# Parses the SilverStripe Security Releases RSS feed for vulnerabilities in the current project's
# composer.lock file.
# 
# Requirements:
#
# Feedparser:    pip install feedparser
# BeautifulSoup: apt-get install python-bs4

from bs4 import BeautifulSoup
import json, sys, feedparser, re

feed_url = 'https://www.silverstripe.org/download/security-releases/rss'

# We use this pseudo constant when no package is given in the RSS advisories
DEFAULT_PACKAGE = 'silverstripe/framework'

# Clean up version constraints
def clean_version(input):
    return re.sub('[^[\d.]', '', input)

# Cleanup package-names
def clean_package(input):
    return input.strip(' :')

with open('./composer.lock', 'r') as composerLockFile:
    json = json.load(composerLockFile)

    feed = feedparser.parse(feed_url)

    if feed.channel == None:
        print 'No feed data found.'
        sys.exit(1)

    for package in json['packages']:
        c_package = package['name']
        c_version = clean_version(package['version'])

        for item in feed['items']:
            soup = BeautifulSoup(item['description'], 'html.parser')
            # All entity-encoded <dd> HTML elements found within an RSS <description> element
            allDDs = soup.find_all('dd')
            # TODO Can also use BS4 to access via class="foo" rather than as a dict/numeric-index
            severity = allDDs[0].string
            identifier = allDDs[1].string
            versionsAffected = allDDs[2].string
            versionsFixed = allDDs[3].string
            advisory_link = item.link

            # Advisories sometimes exclude the package name. Assume this means "silverstripe/framework"
            # Advisories are formatted slightly differently (with/without colon-separated spaces between <package><version>)
            package = re.sub("[\s:]?((>=?)?\s?)?(\d\.?)+(-rc\d)?,?", '', versionsFixed)
            version = re.sub("([^\/]\w+\/[\w-]+(?=[\s:]))+", '', versionsFixed)
            f_package = clean_package(package)
            f_version = clean_version(version)

            # Basic test to see if a package has been stipulated. If not, we assume: "silverstripe/framework"
            if f_package is None or '/' not in f_package:
                f_package = DEFAULT_PACKAGE

            if c_package != f_package:
                continue

            for fixed_version in f_version.split(','):
                is_vulnerable = c_version < fixed_version

                if is_vulnerable:
                    print '[ALERT] %s version %s has a security advisory: %s' % (c_package, c_version, advisory_link)
                    # Break so no further versions need to be checked
                    break
                    sys.exit(1)

from security-advisories.

fabpot avatar fabpot commented on May 28, 2024

I'm going to close this one as we don't have any resources to maintain such a script and it is not our responsibility to create entries for all PHP projects out there. It's a contribution based effort from the community. Now, if the Silverstripe community wants to automate the process of submitting their advisories info, they can do so of course.

from security-advisories.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.