Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: middlewares/referrer-spam
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.1
Choose a base ref
...
head repository: middlewares/referrer-spam
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.2
Choose a head ref
  • 4 commits
  • 6 files changed
  • 1 contributor

Commits on Dec 1, 2020

  1. Copy the full SHA
    2c38b92 View commit details
  2. updated deps

    oscarotero committed Dec 1, 2020
    Copy the full SHA
    2099443 View commit details

Commits on Dec 4, 2020

  1. Copy the full SHA
    3ab55f2 View commit details
  2. new version

    oscarotero committed Dec 4, 2020
    Copy the full SHA
    276a343 View commit details
Showing with 119 additions and 32 deletions.
  1. +76 −0 .github/workflows/main.yaml
  2. +0 −14 .travis.yml
  3. +9 −0 CHANGELOG.md
  4. +2 −6 README.md
  5. +9 −9 composer.json
  6. +23 −3 src/ReferrerSpam.php
76 changes: 76 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: "testing"

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
qa:
name: Quality assurance
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest

- name: Coding Standard
run: composer run-script cs

tests:
name: Tests
runs-on: ubuntu-latest

strategy:
matrix:
php:
- 7.2
- 7.3
- 7.4
composer-args: [ "" ]
include:
- php: 8.0
composer-args: --ignore-platform-reqs
fail-fast: false

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}

- name: Cache PHP dependencies
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest ${{ matrix.composer-args }}

- name: Tests
run: composer test

- name: Tests coverage
run: composer coverage
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.0.2] - 2020-12-04
### Added
- Support for PHP 8

### Fixed
- Removed mindplay/composer-locator dependency [#4]

## [2.0.1] - 2020-10-13
### Fixed
- TypeError on invalid referrer url [#3]
@@ -69,7 +76,9 @@ First version
[#1]: https://github.com/middlewares/referrer-spam/issues/1
[#2]: https://github.com/middlewares/referrer-spam/issues/2
[#3]: https://github.com/middlewares/referrer-spam/issues/3
[#4]: https://github.com/middlewares/referrer-spam/issues/4

[2.0.2]: https://github.com/middlewares/referrer-spam/compare/v2.0.1...v2.0.2
[2.0.1]: https://github.com/middlewares/referrer-spam/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/middlewares/referrer-spam/compare/v1.2.0...v2.0.0
[1.2.0]: https://github.com/middlewares/referrer-spam/compare/v1.1.0...v1.2.0
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@

[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE)
[![Build Status][ico-travis]][link-travis]
[![Quality Score][ico-scrutinizer]][link-scrutinizer]
![Testing][ico-ga]
[![Total Downloads][ico-downloads]][link-downloads]

Middleware to block referrer spammers using [matomo/referrer-spam-blacklist](https://github.com/matomo-org/referrer-spam-blacklist). It returns a `403` response if the url host in the `Referer` header is in the blacklist.
@@ -58,11 +57,8 @@ The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

[ico-version]: https://img.shields.io/packagist/v/middlewares/referrer-spam.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/middlewares/referrer-spam/master.svg?style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/g/middlewares/referrer-spam.svg?style=flat-square
[ico-ga]: https://github.com/middlewares/referrer-spam/workflows/testing/badge.svg
[ico-downloads]: https://img.shields.io/packagist/dt/middlewares/referrer-spam.svg?style=flat-square

[link-packagist]: https://packagist.org/packages/middlewares/referrer-spam
[link-travis]: https://travis-ci.org/middlewares/referrer-spam
[link-scrutinizer]: https://scrutinizer-ci.com/g/middlewares/referrer-spam
[link-downloads]: https://packagist.org/packages/middlewares/referrer-spam
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -18,23 +18,23 @@
"issues": "https://github.com/middlewares/referrer-spam/issues"
},
"require": {
"php": "^7.2",
"php": "^7.2 || ^8.0",
"middlewares/utils": "^3.0",
"matomo/referrer-spam-blacklist": "*",
"mindplay/composer-locator": "^2.1",
"psr/http-server-middleware": "^1.0"
},
"suggest": {
"true/punycode": "~2.0",
"ext-intl": "*"
},
"require-dev": {
"phpunit/phpunit": "^8.1",
"phpunit/phpunit": "^8|^9",
"laminas/laminas-diactoros": "^2.2",
"friendsofphp/php-cs-fixer": "^2.0",
"squizlabs/php_codesniffer": "^3.0",
"oscarotero/php-cs-fixer-config": "^1.0",
"true/punycode": "^2.1"
"true/punycode": "^2.1",
"phpstan/phpstan": "^0.12"
},
"autoload": {
"psr-4": {
@@ -47,11 +47,11 @@
}
},
"scripts": {
"test": [
"phpunit --coverage-text",
"phpcs"
],
"cs": "phpcs",
"cs-fix": "php-cs-fixer fix",
"coverage": "phpunit --coverage-html=coverage"
"phpstan": "phpstan analyse",
"test": "phpunit",
"coverage": "phpunit --coverage-text",
"coverage-html": "phpunit --coverage-html=coverage"
}
}
26 changes: 23 additions & 3 deletions src/ReferrerSpam.php
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@

namespace Middlewares;

use ComposerLocator;
use Middlewares\Utils\Factory;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
@@ -95,9 +94,9 @@ private function encodeIDN(string $domain): string
*/
private static function getBlackList(): array
{
$path = ComposerLocator::getPath('matomo/referrer-spam-blacklist').'/spammers.txt';
$path = self::locateMatomoBlacklist();

if (!is_file($path)) {
if ($path === null) {
// @codeCoverageIgnoreStart
throw new RuntimeException('Unable to locate the matomo referrer spam blacklist file');
// @codeCoverageIgnoreEnd
@@ -111,4 +110,25 @@ private static function getBlackList(): array

return $list;
}

private static function locateMatomoBlacklist(): ?string
{
$file = 'matomo/referrer-spam-blacklist/spammers.txt';

//Development
$path = __DIR__."/../vendor/{$file}";

if (is_file($path)) {
return $path;
}

//Production
$path = __DIR__."/../../../{$file}";

if (is_file($path)) {
return $path;
}

return null;
}
}