Giter VIP home page Giter VIP logo

mixed-content-scanner's Introduction

Scan your site for mixed content

Latest Version on Packagist Tests Total Downloads

This package contains a class that can scan your site for mixed content.

Here's an example of how you can use it:

use Spatie\MixedContentScanner\MixedContentScanner;

$logger = new MixedContentLogger();

$scanner = new MixedContentScanner($logger);

$scanner->scan('https://example.com');

MixedContentLogger is a class containing methods that get called when mixed content is (not) found.

If you don't need a custom implementation but simply want to look for mixed content using a command line tool, take a look at our mixed-content-scanner-cli package.

Support us

Learn how to create a package like this one, by watching our premium video course:

Laravel Package training

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/mixed-content-scanner

How it works under the hood

When scanning a site, the scanner will crawl everypage. On the retrieve html, these elements and attributes will be checked:

  • audio: src
  • embed: src
  • form: action
  • link: href
  • iframe: src
  • img: src, srcset
  • object: data
  • param: value
  • script: src
  • source: src, srcset
  • video: src

If any of those attributes start with http:// the element will be regarded as mixed content.

The package does not scan linked .css or .js files, nor does it take inline <script> or <style> and shortlinks into consideration.

Usage

use Spatie\MixedContentScanner\MixedContentScanner

$logger = new MixedContentLogger();

$scanner = new MixedContentScanner($logger);

$scanner->scan('https://example.com');

That MixedContentScanner accepts an instance of a class that extends \Spatie\MixedContentScannerMixedContentObserver. You should create such a class yourself. Let's take a look at an example implementation.

use Psr\Http\Message\UriInterface;
use Spatie\MixedContentScanner\MixedContent;
use Spatie\MixedContentScanner\MixedContentObserver;

class MyMixedContentLogger extends MixedContentObserver
{
    /**
     * Will be called when mixed content was found.
     * 
     * @param \Spatie\MixedContentScanner\MixedContent $mixedContent
     */
    public function mixedContentFound(MixedContent $mixedContent): void
    {
    }

    /**
     * Will be called when no mixed content was found on the given url.
     * 
     * @param \Psr\Http\Message\UriInterface $crawledUrl
     */
    public function noMixedContentFound(UriInterface $crawledUrl): void
    {
    }

    /**
     * Will be called when the scanner has finished crawling.
     */
    public function finishedCrawling(): void
    {
    }
}

Of course, you should supply a function body to these methods yourself. If you don't need a function just leave it off.

The $mixedContent variable the mixedContentFound class accept is an instance of \Spatie\MixedContentScanner\MixedContent which has these three properties:

  • $elementName: the name of the element that is regarded as mixed content
  • $mixedContentUrl: the url of the element that is regarded as mixed content. For an image this can be the value of src or srcset for a form this can be the value of action, ...
  • $foundOnUrl: the url where the mixed content was found

Customizing the requests

The scanner is powered by our homegrown Crawler which on it's turn leverages Guzzle to perform webrequests. You can pass an array of options to the second argument of MixedContentScanner. These options will be passed to the Guzzle Client.

Here's an example where ssl verification is being turned off.

$scanner = new MixedContentScanner($logger);
$scanner->scan('https://laravel.com', ['verify' => 'false']);

Filtering the crawled urls

By default, the mixed content scanner will crawl all urls of the hostname given. If you want to filter the urls to be crawled, you can pass the scanner a class that extends Spatie\Crawler\CrawlProfile.

Here's the content of that class:

namespace Spatie\Crawler;

use Psr\Http\Message\UriInterface;

abstract class CrawlProfile
{
    /**
     * Determine if the given url should be crawled.
     *
     * @param \Psr\Http\Message\UriInterface $url
     *
     * @return bool
     */
    abstract public function shouldCrawl(UriInterface $url): bool;
}

And here's how you can let the scanner use your profile:

use Spatie\MixedContentScanner\MixedContentScanner;

$logger = new MixedContentLogger();

$scanner = new MixedContentScanner($logger);

$scanner->setCrawlProfile(new MyCrawlProfile);

Customizing the crawler

The scanner is powered by our homegrown Crawler. You can call any methods on the crawler before the crawling process starts by calling configureCrawler on a MixedContentScanner.

use Spatie\Crawler\Crawler;
use Spatie\MixedContentScanner\MixedContentScanner;

$scanner = (new MixedContentScanner($logger))
    ->configureCrawler(function(Crawler $crawler) {
        $crawler->setConcurrency(1) // now all urls will be crawled one by one 
    });

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

The scanner is inspired by mixed-content-scan by Bram Van Damme. Parts of his readme and code were used.

License

The MIT License (MIT). Please see License File for more information.

mixed-content-scanner's People

Contributors

adrianmrn avatar akoepcke avatar brendt avatar codeinnovers avatar freekmurze avatar peter279k avatar samuelnitsche avatar sebastiandedeyne avatar wavehack avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mixed-content-scanner's Issues

MixedContentLogger class missing

Trying to run the example, and I get the following error:

PHP Fatal error:  Uncaught Error: Class 'MixedContentLogger' not found in /home/mcscanner/scan.php:7
Stack trace:
#0 {main}
  thrown in /home/mcscanner/scan.php on line 7

Shortlinks returned as mixed content

Using your lovely tool to scan websites with new SSL for mixed content and I've found lots of sites with tags like this . Shortlinks just tell the search engines an alternative url for the page and do not constitute content so I think showing them as mixed content is an error.

Possibility to scan a model

Thank you very much for your work! I appreciate it! But I do have one question. Is it possible to scan an eloquent model without much effort? Of course I could simply scan the model's URL, but then I would have problems with several models with the same URL.
Thank you for an answer!

demo

Hello

Can you provide a demo for how to use it?

scanner return null

hi i am noob in php can help me
scanner return null
this is my controller
`<?php
namespace App\Http\Controllers;
use App\CustomeClass\MixedContentLogger;
use App\myClass\myClass;
use Ixudra\Curl\Facades\Curl;
use Spatie\MixedContentScanner\MixedContentScanner;
class CheckSSLController extends Controller
{
//

public function CheckPadLock(){

   $url=\request('url');
    $logger = new MixedContentLogger();
    $scanner = new MixedContentScanner($logger);
    $res=$scanner->scan($url);
}

}`

and this is MixedContentLogger class
`<?php
namespace App\CustomeClass;

use Psr\Http\Message\UriInterface;
use Spatie\MixedContentScanner\MixedContent;
use Spatie\MixedContentScanner\MixedContentObserver;

class MixedContentLogger extends MixedContentObserver
{
/**

  • Will be called when mixed content was found.
  • @param \Spatie\MixedContentScanner\MixedContent $mixedContent
    */
    public function mixedContentFound(MixedContent $mixedContent)
    {

}

/**

  • Will be called when no mixed content was found on the given url.
  • @param \Psr\Http\Message\UriInterface $crawledUrl
    */
    public function noMixedContentFound(UriInterface $crawledUrl)
    {

}

/**

  • Will be called when the scanner has finished crawling.
    */
    public function finishedCrawling()
    {

}
}
`

Support HTTP URLs too

Mixed content scanning is valuable for not-yet-migrated websites, to figure out what work they need to do before flipping the switch. Bramus' mixed-content-scan supports this use case.

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.