You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
│ ├── Rules/ # Rule Management on whether we log a query
96
+
│ ├── Scheduler/ # Automated data cleanup and maintenance tasks
95
97
│ ├── Plugin.php # Main plugin class (entry point)
96
98
│ └── Autoload.php # PSR-4 autoloader
97
99
├── tests/ # All test suites
@@ -119,6 +121,12 @@ wpgraphql-logging/
119
121
-**Monolog-powered logging pipeline**
120
122
- Default handler: stores logs in a WordPress table (`{$wpdb->prefix}wpgraphql_logging`).
121
123
124
+
-**Automated data management**
125
+
-**Daily cleanup scheduler**: Automatically removes old logs based on retention settings.
126
+
-**Configurable retention period**: Set how many days to keep log data (default: 30 days).
127
+
-**Manual cleanup**: Admin interface to trigger immediate cleanup of old logs.
128
+
-**Data sanitization**: Remove sensitive fields from logged data for privacy compliance.
129
+
122
130
-**Simple developer API**
123
131
-`Plugin::on()` to subscribe, `Plugin::emit()` to publish, `Plugin::transform()` to modify payloads.
124
132
@@ -127,6 +135,126 @@ wpgraphql-logging/
127
135
128
136
---
129
137
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
-`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: "[email protected]"` → `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
- 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
+
130
258
## Usage
131
259
132
260
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