├── .github ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── SECURITY.md └── workflows │ ├── formats.yml │ └── tests.yml ├── .php-cs-fixer.php ├── LICENSE ├── README.md ├── composer.json ├── phpstan.neon.dist └── src ├── Events └── RickRolled.php ├── Exceptions └── RenderableRickRoll.php ├── Facades └── RickRoll.php ├── LaravelRickRoll.php ├── RickRollServiceProvider.php ├── URL.php └── helpers.php /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone. 8 | ## Our Standards 9 | 10 | Examples of behavior that contributes to creating a positive environment 11 | include: 12 | 13 | * Using welcoming and inclusive language 14 | * Being respectful of differing viewpoints and experiences 15 | * Gracefully accepting constructive criticism 16 | * Focusing on what is best for the community 17 | * Showing empathy towards other community members 18 | 19 | Examples of unacceptable behavior by participants include: 20 | 21 | * The use of sexualized language or imagery and unwelcome sexual attention or 22 | advances 23 | * Trolling, insulting/derogatory comments, and personal or political attacks 24 | * Public or private harassment 25 | * Publishing others' private information, such as a physical or electronic 26 | address, without explicit permission 27 | * Other conduct which could reasonably be considered inappropriate in a 28 | professional setting 29 | 30 | ## Our Responsibilities 31 | 32 | Project maintainers are responsible for clarifying the standards of acceptable 33 | behavior and are expected to take appropriate and fair corrective action in 34 | response to any instances of unacceptable behavior. 35 | 36 | Project maintainers have the right and responsibility to remove, edit, or 37 | reject comments, commits, code, wiki edits, issues, and other contributions 38 | that are not aligned to this Code of Conduct, or to ban temporarily or 39 | permanently any contributor for other behaviors that they deem inappropriate, 40 | threatening, offensive, or harmful. 41 | 42 | ## Scope 43 | 44 | This Code of Conduct applies both within project spaces and in public spaces 45 | when an individual is representing the project or its community. Examples of 46 | representing a project or community include using an official project e-mail 47 | address, posting via an official social media account, or acting as an appointed 48 | representative at an online or offline event. Representation of a project may be 49 | further defined and clarified by project maintainers. 50 | 51 | ## Enforcement 52 | 53 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 54 | reported by contacting the project team at oss+abuse@privagon.fr. All 55 | complaints will be reviewed and investigated and will result in a response that 56 | is deemed necessary and appropriate to the circumstances. The project team is 57 | obligated to maintain confidentiality with regard to the reporter of an incident. 58 | Further details of specific enforcement policies may be posted separately. 59 | 60 | Project maintainers who do not follow or enforce the Code of Conduct in good 61 | faith may face temporary or permanent repercussions as determined by other 62 | members of the project's leadership. 63 | 64 | ## Attribution 65 | 66 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 67 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 68 | 69 | [homepage]: https://www.contributor-covenant.org 70 | 71 | For answers to common questions about this code of conduct, see 72 | https://www.contributor-covenant.org/faq 73 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /.github/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | **PLEASE DON'T DISCLOSE SECURITY-RELATED ISSUES PUBLICLY** 3 | ## Reporting a Vulnerability 4 | If you discover a security vulnerability within our package, please send an email to our Company at hi@felixdorn.fr. All security vulnerabilities will be promptly addressed. 5 | -------------------------------------------------------------------------------- /.github/workflows/formats.yml: -------------------------------------------------------------------------------- 1 | name: Formats 2 | 3 | on: ['push', 'pull_request', 'workflow_dispatch'] 4 | 5 | jobs: 6 | ci: 7 | runs-on: ${{ matrix.os }} 8 | 9 | strategy: 10 | fail-fast: true 11 | matrix: 12 | os: [ubuntu-latest] 13 | php: [8.1] 14 | dependency-version: [prefer-stable] 15 | 16 | name: Formats PHP${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} 17 | 18 | steps: 19 | 20 | - name: Checkout 21 | uses: actions/checkout@v2 22 | 23 | - name: Cache dependencies 24 | uses: actions/cache@v1 25 | with: 26 | path: ~/.composer/cache/files 27 | key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} 28 | 29 | - name: Setup PHP 30 | uses: shivammathur/setup-php@v2 31 | with: 32 | php-version: ${{ matrix.php }} 33 | extensions: dom, mbstring, zip 34 | tools: prestissimo 35 | coverage: pcov 36 | 37 | - name: Install Composer dependencies 38 | run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist 39 | 40 | - name: Coding Style Checks 41 | run: composer test:lint 42 | 43 | - name: Type Checks 44 | run: composer test:types 45 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: ['push', 'pull_request', 'workflow_dispatch'] 4 | 5 | jobs: 6 | ci: 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | fail-fast: true 10 | matrix: 11 | os: [ubuntu-latest] 12 | php: [8.1] 13 | testbench: [6, 7] 14 | dependency-version: [prefer-stable] 15 | 16 | name: Tests PHP${{ matrix.php }} - ${{ matrix.os }} - TestBench ${{ matrix.testbench }} 17 | 18 | steps: 19 | 20 | - name: Checkout 21 | uses: actions/checkout@v2 22 | 23 | - name: Cache dependencies 24 | uses: actions/cache@v1 25 | with: 26 | path: ~/.composer/cache/files 27 | key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} 28 | 29 | - name: Setup PHP 30 | uses: shivammathur/setup-php@v2 31 | with: 32 | php-version: ${{ matrix.php }} 33 | extensions: dom, mbstring, zip 34 | coverage: none 35 | 36 | - name: Install Composer dependencies 37 | run: | 38 | composer require orchestra/testbench:^${{ matrix.testbench }} --dev --no-interaction --prefer-dist 39 | composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist 40 | 41 | - name: Integration Tests 42 | run: php ./vendor/bin/phpunit 43 | -------------------------------------------------------------------------------- /.php-cs-fixer.php: -------------------------------------------------------------------------------- 1 | in(__DIR__ . DIRECTORY_SEPARATOR . 'tests') 5 | ->in(__DIR__ . DIRECTORY_SEPARATOR . 'src') 6 | ->append(['.php_cs']); 7 | 8 | $rules = [ 9 | '@Symfony' => true, 10 | 'phpdoc_no_empty_return' => false, 11 | 'array_syntax' => ['syntax' => 'short'], 12 | 'yoda_style' => false, 13 | 'binary_operator_spaces' => [ 14 | 'operators' => [ 15 | '=>' => 'align', 16 | '=' => 'align', 17 | ], 18 | ], 19 | 'concat_space' => ['spacing' => 'one'], 20 | 'not_operator_with_space' => false, 21 | ]; 22 | 23 | $rules['increment_style'] = ['style' => 'post']; 24 | 25 | return (new PhpCsFixer\Config) 26 | ->setUsingCache(true) 27 | ->setRules($rules) 28 | ->setFinder($finder); 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Félix Dorn 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Rick Astley in Never Gonna Give You UP 2 | 3 | # RickRoll for Laravel 4 | 5 | [![Tests](https://github.com/felixdorn/laravel-rickroll/actions/workflows/tests.yml/badge.svg)](https://github.com/felixdorn/laravel-rickroll/actions/workflows/tests.yml) 6 | [![Formats](https://github.com/felixdorn/laravel-rickroll/actions/workflows/formats.yml/badge.svg)](https://github.com/felixdorn/laravel-rickroll/actions/workflows/formats.yml) 7 | 8 | Rickrolls people trying to break your site. This package is inspired 9 | by [Liam Hammett's tweet](https://twitter.com/LiamHammett/status/1260984553570570240). 10 | 11 | ## Getting started 12 | 13 | You can install the package via composer, if you don't have composer installed, you can download 14 | it [here](https://getcomposer.org): 15 | 16 | ```bash 17 | composer require felixdorn/laravel-rickroll 18 | ``` 19 | 20 | Or by adding a requirement in your `composer.json` : 21 | 22 | ```json 23 | { 24 | "require": { 25 | "felixdorn/laravel-rickroll": "dev-master" 26 | } 27 | } 28 | ``` 29 | 30 | ## We need your knowledge! 31 | 32 | Do you know any well-known url that "hackers" use to gather information/secrets ? Add 33 | these [here](src/LaravelRickRoll.php), thanks! 34 | 35 | ## Usage 36 | 37 | On your `routes/web.php` just add this single line, and we'll handle the rest for you! 38 | 39 | ```php 40 | use Felix\Rickroll\Facades\RickRoll; 41 | 42 | RickRoll::routes(); 43 | ``` 44 | 45 | ### Redirecting to a custom URL 46 | 47 | ```php 48 | use Felix\Rickroll\Facades\RickRoll; 49 | 50 | RickRoll::routes()->redirectsTo('https://mycustom.url'); 51 | ``` 52 | 53 | ### Remove all URLs 54 | 55 | ```php 56 | use Felix\Rickroll\Facades\RickRoll; 57 | 58 | RickRoll::routes()->clear(); 59 | ``` 60 | 61 | ### Adding a URL 62 | 63 | ```php 64 | use Felix\Rickroll\Facades\RickRoll; 65 | 66 | RickRoll::routes()->push('/rickroll') 67 | ->push('/rickroll/{id}', [ 68 | 'id' => '[0-9]+' 69 | ]); 70 | ``` 71 | 72 | ### Helper 73 | 74 | There is a `rickroll` function available if you want to rickroll someone in one of your controllers. 75 | 76 | ```php 77 | rickroll('https://my-custom.url'); 78 | ``` 79 | 80 | You don't need to return anything, it works just like an `abort`. 81 | 82 | ### Events 83 | 84 | We're dispatching an event with the current request when someone is rick-rolled. Just listen 85 | for `Felix\RickRoll\Events\RickRolled` in your `EventServiceProvider` . 86 | 87 | ## Testing 88 | 89 | ``` bash 90 | composer test 91 | ``` 92 | 93 | ## Contributing 94 | 95 | Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. 96 | 97 | ### Security 98 | 99 | If you discover any security related issues, please email hi@felixdorn.fr instead of using the issue tracker. 100 | 101 | ## Credits 102 | 103 | - [Félix Dorn](https://github.com/felixdorn) 104 | - [All Contributors](../../contributors) 105 | 106 | ## License 107 | 108 | The MIT License (MIT). Please see [License File](LICENSE) for more information. 109 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "felixdorn/laravel-rickroll", 3 | "description": "Rickrolls people trying to break your site.", 4 | "keywords": [ 5 | "felixdorn", 6 | "laravel-rickroll" 7 | ], 8 | "homepage": "https://github.com/felixdorn/laravel-rickroll", 9 | "license": "MIT", 10 | "type": "library", 11 | "authors": [ 12 | { 13 | "name": "Félix Dorn", 14 | "email": "hi@felixdorn.fr", 15 | "role": "Developer" 16 | } 17 | ], 18 | "require": { 19 | "php": "^8", 20 | "illuminate/routing": "^8|^9|^10", 21 | "illuminate/support": "^8|^9|^10" 22 | }, 23 | "require-dev": { 24 | "orchestra/testbench": "^6|^7|^8", 25 | "friendsofphp/php-cs-fixer": "^3.6", 26 | "phpunit/phpunit": "^8|^9", 27 | "phpstan/phpstan": "^1.4.6" 28 | }, 29 | "autoload": { 30 | "psr-4": { 31 | "Felix\\RickRoll\\": "src" 32 | }, 33 | "files": [ 34 | "src/helpers.php" 35 | ] 36 | }, 37 | "autoload-dev": { 38 | "psr-4": { 39 | "Felix\\RickRoll\\Tests\\": "tests" 40 | } 41 | }, 42 | "scripts": { 43 | "lint": "php-cs-fixer fix -v", 44 | "test:lint": "php-cs-fixer fix -v --dry-run", 45 | "test:types": "phpstan analyse --ansi --memory-limit=-1", 46 | "test:unit": "phpunit", 47 | "test": [ 48 | "@test:lint", 49 | "@test:types", 50 | "@test:unit" 51 | ], 52 | "test:9x": [ 53 | "composer require orchestra/testbench:^7 --no-interaction --dev --no-update", 54 | "@test" 55 | ], 56 | "test:8x": [ 57 | "composer require orchestra/testbench:^6 --no-interaction --dev --no-update", 58 | "@test" 59 | ] 60 | }, 61 | "config": { 62 | "sort-packages": true 63 | }, 64 | "extra": { 65 | "laravel": { 66 | "aliases": { 67 | "RickRoll": "Felix\\Rickroll\\Facades\\RickRoll" 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /phpstan.neon.dist: -------------------------------------------------------------------------------- 1 | parameters: 2 | level: 8 3 | paths: 4 | - src 5 | 6 | checkMissingIterableValueType: false 7 | -------------------------------------------------------------------------------- /src/Events/RickRolled.php: -------------------------------------------------------------------------------- 1 | request = $request; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Exceptions/RenderableRickRoll.php: -------------------------------------------------------------------------------- 1 | away($this->redirectTo ?? RickRoll::getRedirectURL()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Facades/RickRoll.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | public array $urls = [ 18 | '.env', 19 | '.git', 20 | 'wp-admin', 21 | 'wp-login.php', 22 | 'composer.lock', 23 | 'yarn.lock', 24 | 'package-lock.json', 25 | 'xmlrpc.php', 26 | 'typo3', 27 | '.aws', 28 | ]; 29 | 30 | /** 31 | * The front-end of the library. There is a few options you can specify here 32 | * redirects_to, changes the url where request are rick-rolled 33 | * urls, a list of url to append 34 | * If used in combination of `use_defaults => false`, only these urls will be registered. 35 | */ 36 | public function routes(array $options = []): self 37 | { 38 | if (isset($options['redirects_to'])) { 39 | $this->redirectsTo = $options['redirects_to']; 40 | } 41 | 42 | if (isset($options['use_defaults']) && $options['use_defaults'] === false) { 43 | $this->clear(); 44 | } 45 | 46 | if (isset($options['urls'])) { 47 | $this->withUrls($options['urls']); 48 | } 49 | 50 | return $this; 51 | } 52 | 53 | /** 54 | * Clears all urls. 55 | * 56 | * @return $this 57 | */ 58 | public function clear(): self 59 | { 60 | $this->urls = []; 61 | 62 | return $this; 63 | } 64 | 65 | /** 66 | * Register an url. 67 | * 68 | * @return $this 69 | */ 70 | public function push(string $url, array $constraints = []): self 71 | { 72 | $this->urls[] = new URL($url, $constraints); 73 | 74 | return $this; 75 | } 76 | 77 | /** 78 | * Remove one or more urls from the list 79 | * If a callable is the provided then we filter the array using this callable. 80 | * 81 | * @param string|URL|callable ...$urls 82 | */ 83 | public function remove(...$urls): bool 84 | { 85 | foreach ($urls as $url) { 86 | $this->urls = array_filter( 87 | $this->urls, 88 | is_callable($url) ? $url : fn ($given) => $url !== $given 89 | ); 90 | } 91 | 92 | return false; 93 | } 94 | 95 | /** 96 | * Sets the redirection url. 97 | * 98 | * @return $this 99 | */ 100 | public function redirectsTo(string $url): self 101 | { 102 | $this->redirectsTo = $url; 103 | 104 | return $this; 105 | } 106 | 107 | /** 108 | * Once everything is setup and the object is not used anymore, 109 | * we can register our routes. 110 | */ 111 | public function __destruct() 112 | { 113 | foreach ($this->urls as $url) { 114 | if (is_string($url)) { 115 | $url = URL::createFromURL($url); 116 | } 117 | 118 | $url->register($this->redirectsTo); 119 | } 120 | } 121 | 122 | /** 123 | * Returns the redirect url. 124 | */ 125 | public function getRedirectURL(): string 126 | { 127 | return $this->redirectsTo; 128 | } 129 | 130 | public function getUrls(): array 131 | { 132 | return $this->urls; 133 | } 134 | 135 | public function withUrls(array $urls): self 136 | { 137 | $this->urls = [...$this->urls, ...$urls]; 138 | 139 | return $this; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/RickRollServiceProvider.php: -------------------------------------------------------------------------------- 1 | redirectsTo = $url; 36 | 37 | return $this; 38 | } 39 | 40 | /** 41 | * @internal 42 | */ 43 | public function register(string $redirectsTo): void 44 | { 45 | if (!$this->redirectsTo) { 46 | $this->redirectsTo = $redirectsTo; 47 | } 48 | 49 | Route::any($this->url, fn (Request $request) => $this->handler($request)); 50 | } 51 | 52 | public function handler(Request $request): RedirectResponse 53 | { 54 | event(new RickRolled($request)); 55 | 56 | /* @phpstan-ignore-next-line */ 57 | return redirect()->away($this->redirectsTo); 58 | } 59 | 60 | public function getUrl(): string 61 | { 62 | return $this->url; 63 | } 64 | 65 | public function getConstraints(): array 66 | { 67 | return $this->constraints; 68 | } 69 | 70 | public function getRedirectsTo(): ?string 71 | { 72 | return $this->redirectsTo; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/helpers.php: -------------------------------------------------------------------------------- 1 |