-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit df1e922
Showing
27 changed files
with
9,822 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Dependency Review Action | ||
# | ||
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging. | ||
# | ||
# Source repository: https://github.com/actions/dependency-review-action | ||
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement | ||
name: 'Dependency Review' | ||
on: [pull_request] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
dependency-review: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 'Checkout Repository' | ||
uses: actions/checkout@v3 | ||
- name: 'Dependency Review' | ||
uses: actions/dependency-review-action@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Linter | ||
|
||
on: [push] | ||
|
||
jobs: | ||
php-code-styling: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
|
||
- name: Fix PHP code style issues | ||
uses: aglipanci/[email protected] | ||
|
||
- name: Commit changes | ||
uses: stefanzweifel/git-auto-commit-action@v4 | ||
with: | ||
commit_message: Fix styling |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: phpunit | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
run-tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php: [8.1, 8.2] | ||
laravel: [9.*, 10.*] | ||
include: | ||
- laravel: 10.* | ||
testbench: 8 | ||
- laravel: 9.* | ||
testbench: 7.* | ||
|
||
name: PHP${{ matrix.php }} - Laravel ${{ matrix.laravel }} | ||
|
||
steps: | ||
- name: Update apt | ||
run: sudo apt-get update --fix-missing | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: none | ||
|
||
- name: Setup Problem Matches | ||
run: | | ||
echo "::add-matcher::${{ runner.tool_cache }}/php.json" | ||
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" | ||
- name: Install dependencies | ||
run: | | ||
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update | ||
composer update --prefer-dist --no-interaction --no-suggest | ||
- name: Execute tests | ||
run: vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.phpunit.result.cache | ||
/coverage | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM php:8.1-fpm | ||
|
||
RUN apt-get update \ | ||
&& apt-get -y install libzip-dev zlib1g-dev git zip unzip libicu-dev g++ libbz2-dev libmemcached-dev \ | ||
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \ | ||
|
||
RUN docker-php-ext-configure zip && docker-php-ext-install pdo pdo_mysql zip bz2 intl | ||
|
||
# Get latest Composer | ||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer | ||
|
||
# Set working directory | ||
WORKDIR /var/www | ||
|
||
RUN chown -R www-data:www-data /var/www | ||
|
||
# Expose port 9000 and start php-fpm server | ||
EXPOSE 9000 | ||
CMD ["php-fpm"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 YorCreative | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,261 @@ | ||
<br /> | ||
<br /> | ||
<div align="center"> | ||
<a href="https://github.com/YorCreative"> | ||
<img src="content/logo.png" alt="Logo" width="128" height="128"> | ||
</a> | ||
</div> | ||
<h3 align="center">Laravel Scanator</h3> | ||
|
||
<div align="center"> | ||
<a href="https://github.com/YorCreative/Laravel-Scanator/blob/main/LICENSE.md"><img alt="GitHub license" src="https://img.shields.io/github/license/YorCreative/Laravel-Scanator"></a> | ||
<a href="https://github.com/YorCreative/Laravel-Scanator/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/YorCreative/Laravel-Scanator"></a> | ||
<a href="https://github.com/YorCreative/Laravel-Scanator/issues"><img alt="GitHub issues" src="https://img.shields.io/github/issues/YorCreative/Laravel-Scanator"></a> | ||
<a href="https://github.com/YorCreative/Laravel-Scanator/network"><img alt="GitHub forks" src="https://img.shields.io/github/forks/YorCreative/Laravel-Scanator"></a> | ||
<a href="https://github.com/YorCreative/Laravel-Scanator/actions/workflows/phpunit.yml"><img alt="PHPUnit" src="https://github.com/YorCreative/Laravel-Scanator/actions/workflows/phpunit.yml/badge.svg"></a> | ||
</div> | ||
|
||
A Laravel package that provides functionalities for detecting sensitive information and patterns in the database, helping to ensure data privacy and security by empowering developers to easily integrate database scanning capabilities into their applications and take proactive measures to protect sensitive data. | ||
|
||
## Installation | ||
|
||
install the package via composer: | ||
|
||
```bash | ||
composer require yorcreative/laravel-scanator | ||
``` | ||
|
||
Publish the assets. | ||
|
||
```bash | ||
php artisan vendor:publish --provider="YorCreative\Scanator\ScanatorServiceProvider" | ||
php artisan vendor:publish --provider="YorCreative\Scanator\ScrubberServiceProvider" | ||
``` | ||
|
||
## Configuration | ||
|
||
### Adjusting the Scanators Configuration File | ||
|
||
Adjust the configuration file to suite your application, located in `/config/scanator.php`. | ||
|
||
```php | ||
return [ | ||
'sql' => [ | ||
'ignore_tables' => [ | ||
'failed_jobs', | ||
'migrations' | ||
], | ||
'ignore_columns' => [ | ||
'id', | ||
'created_at', | ||
'updated_at' | ||
], | ||
'ignore_types' => [ | ||
'timestamp' | ||
], | ||
'select' => [ | ||
'low_limit' => 3, | ||
'high_limit' => 10 | ||
], | ||
] | ||
]; | ||
``` | ||
|
||
### Adjusting the Scrubber Configuration File | ||
|
||
Adjust the `regex_loader` field to suite your application, located in `/config/scrubber.php`. | ||
For more information on the Scrubber configuration file, please see the source documentation [here](https://github.com/YorCreative/Laravel-Scrubber). | ||
|
||
```php | ||
return [ | ||
... | ||
'regex_loader' => ['*'], // Opt-in to specific regex classes OR include all with * wildcard. | ||
... | ||
]; | ||
``` | ||
|
||
## Usage | ||
|
||
This package is shipped without implementation. It is shipped as a tool and up to developers to choose how they implement to suite to applications needs. | ||
|
||
### Detection Manager | ||
|
||
The [DetectionManager](https://github.com/YorCreative/Laravel-Scanator/blob/dev/src/Support/DetectionManager.php#L8) | ||
class is an essential component of the Laravel Scanator package. It manages and stores the [Detections](https://github.com/YorCreative/Laravel-Scanator/blob/dev/src/Support/Detection.php#L9) during the scanning process. | ||
It provides methods to record detections, retrieve the list of detections, and obtain the scan start time. | ||
|
||
### Full Database Scan | ||
This package ships with the ability to analyze and build out database schema and then scans for sensitive | ||
information excluding any tables, columns or types from the Scanator configuration file finally to return the | ||
Detection Manager class. | ||
|
||
```php | ||
$detectionManager = Scanator::init(); | ||
|
||
$detections = $detectionManager->getDetections(); | ||
``` | ||
|
||
### Selective Database Scan | ||
|
||
This package ships with the ability to selectively scan tables. | ||
|
||
```php | ||
$detectionManager = new DetectionManager(); | ||
|
||
Scanator::analyze($detectionManager, 'table_name', ['columns', 'to', 'scan']); | ||
|
||
$detections = $detectionManager->getDetections(); | ||
``` | ||
|
||
### Defining Excludable Tables | ||
|
||
The configuration file of this package offers the functionality to define excludable tables, allowing you to exclude them from the scanning process. | ||
|
||
|
||
```php | ||
'ignore_tables' => [ | ||
'failed_jobs', | ||
'migrations' | ||
], | ||
``` | ||
|
||
### Defining Excludable Columns | ||
|
||
Similarly, you can define excludable columns within the configuration file to prevent the package from scanning them. | ||
|
||
```php | ||
'ignore_columns' => [ | ||
'id', | ||
'created_at', | ||
'updated_at' | ||
], | ||
``` | ||
|
||
### Defining Excludable Data Types | ||
|
||
To further refine the scanning process, you can specify excludable data types in the configuration file. | ||
The package will then disregard these data types during scanning. | ||
|
||
```php | ||
'ignore_types' => [ | ||
'timestamp' | ||
], | ||
``` | ||
|
||
### Defining Sample Size | ||
|
||
For greater control over the scanning procedure, the configuration file allows you to define the sample size extracted | ||
from each table. | ||
|
||
```php | ||
'select' => [ | ||
'low_limit' => 3, | ||
'high_limit' => 10 | ||
], | ||
``` | ||
|
||
## Scrubber Documentation | ||
|
||
This package builds on the [RegexRepository](https://github.com/YorCreative/Laravel-Scrubber/blob/main/src/Scrubber.php#L17) provided by the scrubber package. For complete documentation on the scrubber, see [here](https://github.com/YorCreative/Laravel-Scrubber) | ||
|
||
### Regex Class Opt-in | ||
|
||
You have the ability through the scrubber configuration file to define what regex classes you want loaded into the application | ||
when it is bootstrapped. By default, this package ships with a wildcard value. | ||
|
||
### Regex Collection & Defining Opt-in | ||
|
||
To opt in, utilize the static properties on | ||
the [RegexCollection](https://github.com/YorCreative/Laravel-Scrubber/blob/main/src/Repositories/RegexCollection.php) | ||
class. | ||
|
||
```php | ||
'regex_loader' => [ | ||
RegexCollection::$GOOGLE_API, | ||
RegexCollection::$AUTHORIZATION_BEARER, | ||
RegexCollection::$CREDIT_CARD_AMERICAN_EXPRESS, | ||
RegexCollection::$CREDIT_CARD_DISCOVER, | ||
RegexCollection::$CREDIT_CARD_VISA, | ||
RegexCollection::$JSON_WEB_TOKEN | ||
], | ||
``` | ||
|
||
### Creating Custom Extended Classes | ||
|
||
The Scrubber package ships with a command to create custom extended classes and allows further refining of database scans for the Scanator. | ||
|
||
```bash | ||
php artisan make:regex-class {name} | ||
``` | ||
|
||
This command will create a stubbed out class in `App\Scrubber\RegexCollection`. The Scrubber package will autoload | ||
everything from the `App\Scrubber\RegexCollection` folder with the wildcard value on the `regex_loader` array in the | ||
scrubber config file. You will need to provide a `Regex Pattern` and a `Testable String` for the class. | ||
|
||
### Opting Into Custom Extended Classes | ||
|
||
The `regex_loader` array takes strings, not objects. To opt in to specific custom extended regex classes, define the | ||
class name as a string. | ||
|
||
For example if I have a custom extended class as such: | ||
|
||
```php | ||
<?php | ||
|
||
namespace App\Scrubber\RegexCollection; | ||
|
||
use YorCreative\Scrubber\Interfaces\RegexCollectionInterface; | ||
|
||
class TestRegex implements RegexCollectionInterface | ||
{ | ||
public function getPattern(): string | ||
{ | ||
/** | ||
* @todo | ||
* @note return a regex pattern to detect a specific piece of sensitive data. | ||
*/ | ||
return '(?<=basic) [a-zA-Z0-9=:\\+\/-]{5,100}'; | ||
} | ||
|
||
public function getTestableString(): string | ||
{ | ||
/** | ||
* @todo | ||
* @note return a string that can be used to verify the regex pattern provided. | ||
*/ | ||
return 'basic f9Iu+YwMiJEsQu/vBHlbUNZRkN/ihdB1sNTU'; | ||
} | ||
|
||
public function isSecret(): bool | ||
{ | ||
return false; | ||
} | ||
} | ||
``` | ||
|
||
The `regex_loader` array should be defined as such: | ||
|
||
```php | ||
'regex_loader' => [ | ||
RegexCollection::$GOOGLE_API, | ||
RegexCollection::$AUTHORIZATION_BEARER, | ||
RegexCollection::$CREDIT_CARD_AMERICAN_EXPRESS, | ||
RegexCollection::$CREDIT_CARD_DISCOVER, | ||
RegexCollection::$CREDIT_CARD_VISA, | ||
RegexCollection::$JSON_WEB_TOKEN, | ||
'TestRegex' | ||
], | ||
``` | ||
|
||
## Testing | ||
|
||
```bash | ||
composer test | ||
``` | ||
|
||
## Credits | ||
|
||
- [Yorda](https://github.com/yordadev) | ||
- [All Scanator Contributors](../../contributors) | ||
- [All Scrubber Contributors](https://github.com/YorCreative/Laravel-Scrubber/graphs/contributors) | ||
|
Oops, something went wrong.