{"id":19324867,"url":"https://github.com/spatie/mixed-content-scanner","last_synced_at":"2025-04-06T23:16:53.748Z","repository":{"id":24640997,"uuid":"28050386","full_name":"spatie/mixed-content-scanner","owner":"spatie","description":"Scan a HTTPS-site for mixed content","archived":false,"fork":false,"pushed_at":"2023-06-04T12:17:48.000Z","size":151,"stargazers_count":100,"open_issues_count":0,"forks_count":16,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-30T22:11:18.533Z","etag":null,"topics":["https","mixed-content-error","scan"],"latest_commit_sha":null,"homepage":"https://spatie.be/open-source","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"spatie"}},"created_at":"2014-12-15T18:36:21.000Z","updated_at":"2025-03-20T07:06:29.000Z","dependencies_parsed_at":"2024-12-31T01:19:47.706Z","dependency_job_id":"66ca7cbd-a80f-4564-936e-ee34759819d2","html_url":"https://github.com/spatie/mixed-content-scanner","commit_stats":{"total_commits":133,"total_committers":9,"mean_commits":"14.777777777777779","dds":"0.23308270676691734","last_synced_commit":"02a23e5432276e14f54f74ae09fc0ea02481e2a6"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fmixed-content-scanner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fmixed-content-scanner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fmixed-content-scanner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fmixed-content-scanner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/mixed-content-scanner/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247563935,"owners_count":20958971,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["https","mixed-content-error","scan"],"created_at":"2024-11-10T02:07:16.825Z","updated_at":"2025-04-06T23:16:53.724Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie"],"categories":[],"sub_categories":[],"readme":"# Scan your site for mixed content\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/mixed-content-scanner.svg?style=flat-square)](https://packagist.org/packages/spatie/mixed-content-scanner)\n![Tests](https://github.com/spatie/mixed-content-scanner/workflows/Tests/badge.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/mixed-content-scanner.svg?style=flat-square)](https://packagist.org/packages/spatie/mixed-content-scanner)\n\nThis package contains a class that can scan your site for [mixed content](https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content).\n\nHere's an example of how you can use it:\n\n```php\nuse Spatie\\MixedContentScanner\\MixedContentScanner;\n\n$logger = new MixedContentLogger();\n\n$scanner = new MixedContentScanner($logger);\n\n$scanner-\u003escan('https://example.com');\n```\n\n`MixedContentLogger` is a class containing methods that get called when mixed content is (not) found. \n\nIf 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](https://github.com/spatie/mixed-content-scanner-cli).\n\n## Support us\n\nLearn how to create a package like this one, by watching our premium video course:\n\n[![Laravel Package training](https://spatie.be/github/package-training.jpg)](https://laravelpackage.training)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe 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](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/mixed-content-scanner\n```\n\n## How it works under the hood\n\nWhen scanning a site, the scanner will crawl everypage. On the retrieve html, these elements and attributes will be checked:\n\n- `audio`: `src`\n- `embed`: `src`\n- `form`: `action`\n- `link`: `href`\n- `iframe`: `src`\n- `img`: `src`, `srcset`\n- `object`: `data`\n- `param`: `value`\n- `script`: `src`\n- `source`: `src`, `srcset`\n- `video`: `src`\n\nIf any of those attributes start with `http://` the element will be regarded as mixed content.\n\nThe package does not scan linked `.css` or `.js` files, nor does it take inline `\u003cscript\u003e` or `\u003cstyle\u003e` and [shortlinks](http://microformats.org/wiki/rel-shortlink) into consideration.\n\n## Usage\n\n```php\nuse Spatie\\MixedContentScanner\\MixedContentScanner\n\n$logger = new MixedContentLogger();\n\n$scanner = new MixedContentScanner($logger);\n\n$scanner-\u003escan('https://example.com');\n```\n\nThat `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.\n\n```php\nuse Psr\\Http\\Message\\UriInterface;\nuse Spatie\\MixedContentScanner\\MixedContent;\nuse Spatie\\MixedContentScanner\\MixedContentObserver;\n\nclass MyMixedContentLogger extends MixedContentObserver\n{\n    /**\n     * Will be called when mixed content was found.\n     * \n     * @param \\Spatie\\MixedContentScanner\\MixedContent $mixedContent\n     */\n    public function mixedContentFound(MixedContent $mixedContent): void\n    {\n    }\n\n    /**\n     * Will be called when no mixed content was found on the given url.\n     * \n     * @param \\Psr\\Http\\Message\\UriInterface $crawledUrl\n     */\n    public function noMixedContentFound(UriInterface $crawledUrl): void\n    {\n    }\n\n    /**\n     * Will be called when the scanner has finished crawling.\n     */\n    public function finishedCrawling(): void\n    {\n    }\n}\n```\n\nOf course, you should supply a function body to these methods yourself. If you don't need a function just leave it off.\n\nThe `$mixedContent` variable the `mixedContentFound` class accept is an instance of `\\Spatie\\MixedContentScanner\\MixedContent` which has these three properties:\n\n- `$elementName`: the name of the element that is regarded as mixed content\n- `$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`, ...\n- `$foundOnUrl`: the url where the mixed content was found\n\n### Customizing the requests\n\nThe scanner is powered by [our homegrown Crawler](https://github.com/spatie/crawler) which on it's turn leverages [Guzzle](http://docs.guzzlephp.org/en/stable/) to perform webrequests.\nYou can pass an array of options to the second argument of `MixedContentScanner`. These options will be passed to the Guzzle Client. \n\nHere's an example where ssl verification is being turned off.\n\n```php\n$scanner = new MixedContentScanner($logger);\n$scanner-\u003escan('https://laravel.com', ['verify' =\u003e 'false']);\n```\n\n### Filtering the crawled urls\n\nBy 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`.\n\nHere's the content of that class:\n\n```php\nnamespace Spatie\\Crawler;\n\nuse Psr\\Http\\Message\\UriInterface;\n\nabstract class CrawlProfile\n{\n    /**\n     * Determine if the given url should be crawled.\n     *\n     * @param \\Psr\\Http\\Message\\UriInterface $url\n     *\n     * @return bool\n     */\n    abstract public function shouldCrawl(UriInterface $url): bool;\n}\n```\n\nAnd here's how you can let the scanner use your profile:\n\n```php\nuse Spatie\\MixedContentScanner\\MixedContentScanner;\n\n$logger = new MixedContentLogger();\n\n$scanner = new MixedContentScanner($logger);\n\n$scanner-\u003esetCrawlProfile(new MyCrawlProfile);\n```\n\n## Customizing the crawler\n\nThe scanner is powered by [our homegrown Crawler](https://github.com/spatie/crawler). You can call any methods on the crawler before the crawling process starts by calling `configureCrawler` on a `MixedContentScanner`.\n\n```php\nuse Spatie\\Crawler\\Crawler;\nuse Spatie\\MixedContentScanner\\MixedContentScanner;\n\n$scanner = (new MixedContentScanner($logger))\n    -\u003econfigureCrawler(function(Crawler $crawler) {\n        $crawler-\u003esetConcurrency(1) // now all urls will be crawled one by one \n    });\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Testing\n\n``` bash\ncomposer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Postcardware\n\nYou'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.\n\nOur address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.\n\nWe publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\nThe scanner is inspired by [mixed-content-scan](https://github.com/bramus/mixed-content-scan) by [Bram Van Damme](https://github.com/bramus). Parts of his readme and code were used.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fmixed-content-scanner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Fmixed-content-scanner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fmixed-content-scanner/lists"}