Menu

Tree [df4f9f] develop v1.2.0 /
 History

HTTPS access


File Date Author Commit
 .github 2025-04-25 Milen Karaganski Milen Karaganski [712645] Updates the security policy to reflect current ...
 .husky 2025-04-25 Milen Karaganski Milen Karaganski [b6d608] Initial package files
 config 2025-04-26 Milen Karaganski Milen Karaganski [5bbc83] Implements blacklist modes and expands word lis...
 src 2025-04-26 Milen Karaganski Milen Karaganski [1598df] Refactors blacklist matching to use whole word ...
 tests 2025-04-26 Milen Karaganski Milen Karaganski [1598df] Refactors blacklist matching to use whole word ...
 .gitignore 2025-04-26 Milen Karaganski Milen Karaganski [5bbc83] Implements blacklist modes and expands word lis...
 CHANGELOG.md 2025-04-26 Milen Karaganski Milen Karaganski [df4f9f] Improve documentation and clarify default confi...
 CODEOWNERS 2025-04-25 Milen Karaganski Milen Karaganski [712645] Updates the security policy to reflect current ...
 CODE_OF_CONDUCT.md 2025-04-25 Milen Karaganski Milen Karaganski [712645] Updates the security policy to reflect current ...
 CONTRIBUTING.md 2025-04-25 Milen Karaganski Milen Karaganski [712645] Updates the security policy to reflect current ...
 LICENSE.md 2025-04-25 Milen Karaganski Milen Karaganski [b6d608] Initial package files
 PULL_REQUEST_TEMPLATE.md 2025-04-25 Milen Karaganski Milen Karaganski [712645] Updates the security policy to reflect current ...
 README.md 2025-04-26 Milen Karaganski Milen Karaganski [df4f9f] Improve documentation and clarify default confi...
 SECURITY.md 2025-04-26 Milen Karaganski Milen Karaganski [df4f9f] Improve documentation and clarify default confi...
 composer.json 2025-04-26 Milen Karaganski Milen Karaganski [1598df] Refactors blacklist matching to use whole word ...
 duster.json 2025-04-26 Milen Karaganski Milen Karaganski [5bbc83] Implements blacklist modes and expands word lis...
 lint-staged.config.js 2025-04-25 Milen Karaganski Milen Karaganski [b6d608] Initial package files
 package.json 2025-04-25 Milen Karaganski Milen Karaganski [b6d608] Initial package files
 phpunit.xml 2025-04-26 Milen Karaganski Milen Karaganski [5bbc83] Implements blacklist modes and expands word lis...
 pint.json 2025-04-25 Milen Karaganski Milen Karaganski [b6d608] Initial package files

Read Me

Laravel Blacklist

A Laravel package for blacklist validation of user input. Includes both system blacklist words and profanity/offensive
terms, with the flexibility to choose which lists to use. Uses whole word matching to prevent false positives.

Installation

You can install the package via composer:

composer require milenmk/laravel-blacklist

Configuration

The package works out of the box with default settings, but you can customize it by publishing the config file:

php artisan vendor:publish --tag=blacklist-config

This will create a config/blacklist.php file where you can:

  1. Choose which word lists to use (system blacklist, profanity, or both)
  2. Customize the blacklisted terms in each list

Note: If you don't publish the config file, the package will use the default configuration with the 'blacklist' mode enabled.

Configuration Options

The package provides three modes for filtering content:

// config/blacklist.php
return [
    // Choose which lists to use: 'blacklist', 'profanity', or 'both'
    'mode' => 'blacklist',

    // System blacklist words (usernames, reserved terms, etc.)
    'blacklist' => [
        'admin',
        'system',
        // ...
    ],

    // Profanity and offensive terms
    'profanity' => [
        // Common profanity words
        // ...
    ],
];

Usage

use Milenmk\LaravelBlacklist\BlacklistService;

class YourController
{
    protected BlacklistService $blacklistService;

    public function __construct(BlacklistService $blacklistService)
    {
        $this->blacklistService = $blacklistService;
    }

    public function store(Request $request)
    {
        // Validate request...

        // Check fields against blacklisted words
        $blacklistErrors = $this->blacklistService->checkFields([
            'name' => $request->input('name'),
            'email' => $request->input('email'),
            // Add any other fields you want to check
        ]);

        if (!empty($blacklistErrors)) {
            return redirect()->back()->withErrors($blacklistErrors);
        }

        // Continue with your logic...
    }
}

Advanced Usage

Custom Log Channel

You can specify a custom log channel:

$blacklistErrors = $this->blacklistService->checkFields([
    'name' => $request->input('name'),
    'email' => $request->input('email'),
], 'security');

Switching Modes

You can change the filtering mode in your config file:

// config/blacklist.php
'mode' => 'blacklist', // Only check system blacklist words
// OR
'mode' => 'profanity', // Only check profanity/offensive words
// OR
'mode' => 'both',      // Check both lists

The error messages will indicate which list the matched term belongs to:

  • "The {field} contains the blacklisted word: "{term}""
  • "The {field} contains the profanity word: "{term}""

Word Matching

This package uses whole word boundary matching to prevent false positives. For example:
- "admin" will match in "admin user" but not in "administrator" or "badminton"
- "damn" will match in "that's damn good" but not in "condamnation"

This ensures that legitimate content isn't incorrectly flagged while still catching problematic terms.

License

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

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.