Skip to content

Commit 5d7851f

Browse files
committed
Added docs for data sanitisation.
1 parent 307d83c commit 5d7851f

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

plugins/wpgraphql-logging/README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,126 @@ wpgraphql-logging/
135135

136136
---
137137

138+
## Data Sanitization
139+
140+
WPGraphQL Logging includes robust data sanitization capabilities to help you protect sensitive information while maintaining useful logs for debugging and monitoring. The sanitization system allows you to automatically clean, anonymize, or remove sensitive fields from log records before they are stored.
141+
142+
### Why Data Sanitization Matters
143+
144+
When logging GraphQL requests, context data often contains sensitive information such as:
145+
- User authentication tokens
146+
- Personal identification information (PII)
147+
- Password fields
148+
- Session data
149+
- Internal system information
150+
151+
Data sanitization ensures compliance with privacy regulations (GDPR, CCPA) and security best practices while preserving the debugging value of your logs.
152+
153+
### Sanitization Methods
154+
155+
The plugin offers two sanitization approaches:
156+
157+
#### 1. Recommended Rules (Default)
158+
Pre-configured rules that automatically sanitize common WordPress and WPGraphQL sensitive fields:
159+
- `request.app_context.viewer.data` - User data object
160+
- `request.app_context.viewer.allcaps` - User capabilities
161+
- `request.app_context.viewer.cap_key` - Capability keys
162+
- `request.app_context.viewer.caps` - User capability array
163+
164+
#### 2. Custom Rules
165+
Define your own sanitization rules using dot notation to target specific fields:
166+
167+
**Field Path Examples:**
168+
```
169+
variables.password
170+
request.headers.authorization
171+
user.email
172+
variables.input.creditCard
173+
```
174+
175+
### Sanitization Actions
176+
177+
For each field, you can choose from three sanitization actions:
178+
179+
| Action | Description | Example |
180+
|--------|-------------|---------|
181+
| **Remove** | Completely removes the field from logs | `password: "secret123"`*field removed* |
182+
| **Anonymize** | Replaces value with `***` | `email: "user@example.com"``email: "***"` |
183+
| **Truncate** | Limits string length to 47 characters + `...` | `longText: "Very long text..."``longText: "Very long text that gets cut off here and mo..."` |
184+
185+
### Configuration
186+
187+
Enable and configure data sanitization through the WordPress admin:
188+
189+
1. Navigate to **GraphQL Logging → Settings**
190+
2. Click the **Data Management** tab
191+
3. Enable **Data Sanitization**
192+
4. Choose your sanitization method:
193+
- **Recommended**: Uses pre-configured rules for common sensitive fields
194+
- **Custom**: Define your own field-specific rules
195+
196+
#### Custom Configuration Fields
197+
198+
When using custom rules, configure the following fields:
199+
200+
- **Fields to Remove**: Comma-separated list of field paths to completely remove
201+
- **Fields to Anonymize**: Comma-separated list of field paths to replace with `***`
202+
- **Fields to Truncate**: Comma-separated list of field paths to limit length
203+
204+
**Example Configuration:**
205+
```
206+
Remove: variables.password, request.headers.authorization
207+
Anonymize: user.email, variables.input.personalInfo
208+
Truncate: query, variables.input.description
209+
```
210+
211+
### Developer Hooks
212+
213+
Customize sanitization behavior using WordPress filters:
214+
215+
```php
216+
// Enable/disable sanitization programmatically
217+
add_filter( 'wpgraphql_logging_data_sanitization_enabled', function( $enabled ) {
218+
return current_user_can( 'manage_options' ) ? false : $enabled;
219+
});
220+
221+
// Modify recommended rules
222+
add_filter( 'wpgraphql_logging_data_sanitization_recommended_rules', function( $rules ) {
223+
$rules['custom.sensitive.field'] = 'remove';
224+
return $rules;
225+
});
226+
227+
// Modify all sanitization rules
228+
add_filter( 'wpgraphql_logging_data_sanitization_rules', function( $rules ) {
229+
// Add additional rules or modify existing ones
230+
$rules['request.custom_header'] = 'anonymize';
231+
return $rules;
232+
});
233+
234+
// Modify the final log record after sanitization
235+
add_filter( 'wpgraphql_logging_data_sanitization_record', function( $record ) {
236+
// Additional processing after sanitization
237+
return $record;
238+
});
239+
```
240+
241+
### Performance Considerations
242+
243+
- Sanitization runs on every log record when enabled
244+
- Complex nested field paths may impact performance on high-traffic sites
245+
- Consider using recommended rules for optimal performance
246+
- Test custom rules thoroughly to ensure they target the intended fields
247+
248+
### Security Best Practices
249+
250+
1. **Review logs regularly** to ensure sanitization is working as expected
251+
2. **Test field paths** in a development environment before applying to production
252+
3. **Use remove over anonymize** for highly sensitive data
253+
4. **Monitor performance impact** when implementing extensive custom rules
254+
5. **Keep rules updated** as your GraphQL schema evolves
255+
256+
---
257+
138258
## Usage
139259

140260
WPGraphQL Logging Plugin is highly configurable and extendable and built with developers in mind to allow them to modify, change or add data, loggers etc to this plugin. Please read the docs below:

0 commit comments

Comments
 (0)