Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/PIIRedactor/src/Defaults/PIIRedactorDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static function values(): array
'api_key',
'bearer_token',
'mac_address',
'url',
],
'block_entities' => [
'credit_card',
Expand Down
1 change: 1 addition & 0 deletions src/PIIRedactor/src/Enums/EntityTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ enum EntityTypes: string
case IP_ADDRESS = 'ip_address';
case PHONE = 'phone';
case MAC_ADDRESS = 'mac_address';
case URL = 'url';
}
4 changes: 4 additions & 0 deletions src/PIIRedactor/src/PIIRedactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ protected function defaultDetectors(): array
EntityTypes::MAC_ADDRESS->value,
'/\b(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}\b/'
),
new RegexDetector(
EntityTypes::URL->value,
'/\b(?:https?:\/\/|www\.)[a-zA-Z0-9+&@#\/%?=~_|!:,.;]*[a-zA-Z0-9+&@#\/%=~_|]|\b(?<![a-zA-Z0-9@])(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(?:\/[a-zA-Z0-9+&@#\/%?=~_|!:,.;]*[a-zA-Z0-9+&@#\/%=~_|])?\b/'
),
];
}

Expand Down
19 changes: 19 additions & 0 deletions src/PIIRedactor/tests/PIIRedactorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ function (AgentPrompt $prompt) use (&$forwardedPrompt): string {
expect($forwardedPrompt->prompt)->toBe('The router MAC is [MAC_ADDRESS_1]');
});

it('redacts URLs by default', function (): void {
Log::shouldReceive('warning')->once();

$redactor = new PIIRedactor;

$forwardedPrompt = null;

$redactor->handle(
makePIIRedactorAgentPrompt('Look at http://example.com, check the page https://example.com, visit the site at www.example.com, or https://127.0.0.1:8080, or view the example.com/dashboard.'),
function (AgentPrompt $prompt) use (&$forwardedPrompt): string {
$forwardedPrompt = $prompt;

return 'continued';
},
);

expect($forwardedPrompt->prompt)->toBe('Look at [URL_1], check the page [URL_2], visit the site at [URL_3], or [URL_4], or view the [URL_5].');
});

it('blocks credit cards by default', function (): void {
Log::shouldReceive('warning')->once();

Expand Down
1 change: 1 addition & 0 deletions src/Support/config/intercept.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
'api_key',
'bearer_token',
'mac_address',
'url',
],

/**
Expand Down
Loading