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
Copy file name to clipboardExpand all lines: plugins/wpgraphql-logging/README.md
+120Lines changed: 120 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -135,6 +135,126 @@ wpgraphql-logging/
135
135
136
136
---
137
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: "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
- 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
+
138
258
## Usage
139
259
140
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