YorCreative / Laravel-Scrubber

A Laravel package to scrub sensitive information that breaks operational security policies from being leaked on accident or not by developers.
MIT License
140 stars 12 forks source link

NOT SCRUBBING AT ALL #17

Closed Whizboy-Arnold closed 1 year ago

Whizboy-Arnold commented 1 year ago

It seems after the latest update the tool broke, I thought it was not seeing the parts to redact in the logs yet but no. This is with the vanilla configuration. What is going on well is now i can get my logs on any channel and especially, papertrail, Yes this is good: but now it seems that it stopped redacting be it on local ie single channel or papertrail. Mark you this time I even tried to directly fix it to the RegexCollection class as a hack like last time, it seems just not getting invoked in the first place. Please check out on it.

Also am writing a custom reducter This is want to work:

'regex_loader' => [
        '*',
        "CustomRegexReducter", ///tried this not working
        CustomRegexReducter::class, ///tried this still not working
    ], 

This is tried with a very simple regex as last time:

<?php

// namespace App\Scrubber\RegexCollection;

namespace YorCreative\Scrubber\RegexCollection;

use YorCreative\Scrubber\Interfaces\RegexCollectionInterface;

class CustomRegexReducter implements RegexCollectionInterface
{
    public function getPattern(): string
    {
        /**
         * @todo
         * @note return a regex pattern to detect a specific piece of sensitive data.
         */
        return "process";
    }

    public function getTestableString(): string
    {
        /**
         * @todo
         * @note return a string that can be used to verify the regex pattern provided.
         */
        return "process";
    }

    public function isSecret(): bool
    {
        return false;
    }
}

However I suppose it wont work unless the above is resolved.

Trying to debug what could be wrong i added several dd through out the code, maybe you could:

CHECK FOR COVERAGE:

image

it seems the code is not even reaching this point, that dd("registering") //check above imageis not called on the callback unless am wrong.

yordadev commented 1 year ago

Hi @Whizboy-Arnold

It seems you commented out the correct namespace in your custom extended regex class.

namespace YorCreative\Scrubber\RegexCollection; is not the correct namespace.

I point you to how the strategy pattern is instantiating the custom class here:

In regards to your CHECK FOR COVERAGE: image -- I'm not entirely sure what you did while debugging but I added the same dd's in on a fresh laravel install w/ just a vanilla version of this package.

1ede750705e4c67145b700cae195eb1a

In regards to defining what regex classes you want in your configuration file (I will make a note to update the readme to clearly say this), you cannot have a wildcard + classes. This is because of how the strategy pattern handling this is working. If you are not familiar with strategy patterns, I refer you to my favorite design pattern website.

I do see a misleading bug though with that being said in the custom regex class loader. It is currently always loading your custom classes, without regard to the config regex_loader array if there are any custom regex classes in the App\Scrubber\RegexCollection namespace. I will get a PR going to update this to respect what classes are defined in the regex_loader. With that being said, this is not a functionality breaking bug and the scrubber just loads all the custom classes, if any, always.

For example:

Here the core regex class loader is respecting what is defined in the config regex_loader field.

Here all the custom classes that are defined in the App\Scrubber\RegexCollection namespace are being loaded whenever it detects any.

If you still are having issues, you can find me (@yorda) in my discord server. Here is an invite link: https://discord.gg/qRmsXmmd

yordadev commented 1 year ago

Pushed some changes in with v2.2.1 as seen here: #18

Whizboy-Arnold commented 1 year ago

hello, could you open the discord I still have problems with the tool working

yordadev commented 1 year ago

hello, could you open the discord I still have problems with the tool working

@Whizboy-Arnold https://discord.gg/67MqSuu7bx