PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / vendor / wp-media / mcp-oauth / inc / Auth / ParseBodyTrait.php

ParseBodyTrait.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF trunk, at vendor/wp-media/mcp-oauth/inc/Auth/ParseBodyTrait.php

41 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OAuth Request Body Parser.
4 *
5 * Shared logic for parsing application/json or application/x-www-form-urlencoded
6 * request bodies in OAuth endpoints (TokenEndpoint, RevokeEndpoint).
7 */
8
9 declare(strict_types=1);
10
11 namespace WPMedia\MCP\OAuth\Auth;
12
13 /**
14 * Provides parse_body() to OAuth endpoint classes.
15 */
16 trait ParseBodyTrait {
17
18 /**
19 * Parse the request body from either JSON or form-encoded content.
20 *
21 * JSON bodies are capped at 32 KB to prevent memory exhaustion from
22 * oversized payloads; form-encoded bodies are read from $_POST which
23 * PHP already limits via the post_max_size ini setting.
24 *
25 * @return array<string, mixed> Associative array of body parameters.
26 */
27 private function parse_body(): array {
28 $content_type = isset( $_SERVER['CONTENT_TYPE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['CONTENT_TYPE'] ) ) : '';
29
30 if ( false !== strpos( $content_type, 'application/json' ) ) {
31 $raw = substr( (string) file_get_contents( 'php://input' ), 0, 32768 ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
32 $body = json_decode( '' !== $raw ? $raw : '{}', true );
33 return is_array( $body ) ? $body : [];
34 }
35
36 // Form-encoded (application/x-www-form-urlencoded).
37 // phpcs:ignore WordPress.Security.NonceVerification.Missing
38 return array_map( 'sanitize_text_field', wp_unslash( $_POST ) );
39 }
40 }
41