dolibarr 25.0.0-alpha
PrivacyGuard Class Reference

Class to manage privacy data masking and unmasking. More...

Public Member Functions

 mask ($text)
 Mask sensitive GDPR data in the query.
 
 unmask ($jsonString)
 Restore real data from a masked string.
 
 unmaskAiResponse ($text)
 Unmasks a string from an AI response, handling cases where the AI might have stripped the [[ and ]] delimiters from a token.
 
 maskNames ($text, $names)
 Mask the names of the objects carried in this payload.
 

Private Member Functions

 maskCreditCardCallback (array $matches)
 Callback function for preg_replace_callback to mask credit cards.
 
 passesLuhnCheck ($number)
 Validates a number string using the Luhn algorithm.
 
 startSession ()
 Start the masking session for this guard instance, once.
 
 createToken ($value, $type)
 Create a unique token and store the original value in the map.
 

Detailed Description

Class to manage privacy data masking and unmasking.

Definition at line 29 of file privacy_guard.class.php.

Member Function Documentation

◆ createToken()

PrivacyGuard::createToken ( $value,
$type )
private

Create a unique token and store the original value in the map.

Parameters
string$valueThe original sensitive value.
string$typeThe type of data (e.g., 'EMAIL').
Returns
string The generated token (e.g., [[EMAIL_1a2b]]).

Definition at line 619 of file privacy_guard.class.php.

Referenced by mask(), maskCreditCardCallback(), and maskNames().

◆ mask()

PrivacyGuard::mask ( $text)

Mask sensitive GDPR data in the query.

This method iterates through a series of patterns to find and replace sensitive data with tokens.

Parameters
string$textThe input string containing potentially sensitive data.
Returns
string The masked string with tokens replacing sensitive data.
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string
Parameters
array<int,string>$m
Returns
string

Definition at line 59 of file privacy_guard.class.php.

References createToken(), and startSession().

◆ maskCreditCardCallback()

PrivacyGuard::maskCreditCardCallback ( array $matches)
private

Callback function for preg_replace_callback to mask credit cards.

It first validates the number using the Luhn algorithm.

Parameters
array<int,string>$matches The regex matches array.
Returns
string The token if valid, otherwise the original string.

Definition at line 511 of file privacy_guard.class.php.

References createToken(), and passesLuhnCheck().

◆ maskNames()

PrivacyGuard::maskNames ( $text,
$names )

Mask the names of the objects carried in this payload.

Thirdparty and product names are arbitrary strings: no pattern can recognize them, so they are masked from a dictionary built out of the values actually present in the text. Longest first, so "ACME Ltd" is replaced before "ACME".

Parameters
string$textText to mask.
array<string>$names Candidate names to look for.
Returns
string Masked text.
Returns
int

Definition at line 649 of file privacy_guard.class.php.

References createToken(), dol_strlen(), and startSession().

◆ passesLuhnCheck()

PrivacyGuard::passesLuhnCheck ( $number)
private

Validates a number string using the Luhn algorithm.

Parameters
string$numberThe number string, can contain spaces or hyphens.
Returns
bool True if the number is valid, false otherwise.

Definition at line 528 of file privacy_guard.class.php.

Referenced by maskCreditCardCallback().

◆ startSession()

PrivacyGuard::startSession ( )
private

Start the masking session for this guard instance, once.

Returns
void

Definition at line 599 of file privacy_guard.class.php.

References dol_hash(), and dol_substr().

Referenced by mask(), and maskNames().

◆ unmask()

PrivacyGuard::unmask ( $jsonString)

Restore real data from a masked string.

This method is stateful and relies on the map generated by the preceding mask() call.

Parameters
string$jsonStringThe string containing tokens to be replaced.
Returns
string The unmasked string with original data restored.

Definition at line 491 of file privacy_guard.class.php.

Referenced by unmaskAiResponse().

◆ unmaskAiResponse()

PrivacyGuard::unmaskAiResponse ( $text)

Unmasks a string from an AI response, handling cases where the AI might have stripped the [[ and ]] delimiters from a token.

Parameters
string$textThe string to unmask.
Returns
string The fully unmasked string.

Definition at line 569 of file privacy_guard.class.php.

References unmask().


The documentation for this class was generated from the following file: