Skip to content

Commit 0591625

Browse files
committed
Fixed Data Sanisation issues.
1 parent 0128d2c commit 0591625

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

plugins/wpgraphql-logging/src/Admin/View/List/ListTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ public function get_memory_usage(WordPressDatabaseEntity $item): string {
392392
public function get_request_headers(WordPressDatabaseEntity $item): string {
393393
$extra = $item->get_extra();
394394
$request_headers = $extra['request_headers'] ?? [];
395-
if ( ! is_array( $request_headers ) ) {
395+
if ( ! is_array( $request_headers ) || empty( $request_headers ) ) {
396396
return '';
397397
}
398398

plugins/wpgraphql-logging/src/Logger/Processors/DataSanitizationProcessor.php

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -124,33 +124,20 @@ protected function apply_rule(array &$data, string $key, string $rule): void {
124124

125125
$keys = explode( '.', $key );
126126
$last_key = array_pop( $keys );
127-
$current = $this->navigate_to_parent( $data, $keys );
128127

129-
if ( null === $current || ! array_key_exists( $last_key, $current ) ) {
130-
return;
131-
}
132-
133-
$this->apply_sanitization_rule( $current, $last_key, $rule );
134-
}
135-
136-
/**
137-
* Navigate to the parent array of the target key.
138-
*
139-
* @param array<string, mixed> $data The data array to navigate.
140-
* @param array<string> $keys The keys to navigate through.
141-
*
142-
* @return array<string, mixed>|null The parent array or null if not found.
143-
*/
144-
protected function &navigate_to_parent(array &$data, array $keys): ?array {
145128
$current = &$data;
146129
foreach ( $keys as $segment ) {
147130
if ( ! is_array( $current ) || ! isset( $current[ $segment ] ) ) {
148-
$null = null;
149-
return $null;
131+
return;
150132
}
151133
$current = &$current[ $segment ];
152134
}
153-
return $current;
135+
136+
if ( ! is_array( $current ) || ! array_key_exists( $last_key, $current ) ) {
137+
return;
138+
}
139+
140+
$this->apply_sanitization_rule( $current, $last_key, $rule );
154141
}
155142

156143
/**
@@ -199,8 +186,8 @@ public function __invoke( LogRecord $record ): LogRecord {
199186
return $record;
200187
}
201188

202-
$context = $record['context'] ?? [];
203-
$extra = $record['extra'] ?? [];
189+
$context = $record->context;
190+
$extra = $record->extra;
204191
foreach ( $rules as $key => $rule ) {
205192
$this->apply_rule( $context, $key, $rule );
206193
$this->apply_rule( $extra, $key, $rule );

0 commit comments

Comments
 (0)