Skip to content

Commit 4378eb1

Browse files
author
Joe McGill
authored
Merge branch 'develop' into update/composer-dependencies
2 parents 97e24d2 + 02414d5 commit 4378eb1

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

Diff for: .phpcs.ruleset.xml

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
https://github.com/PHPCompatibility/PHPCompatibilityWP -->
2525
<rule ref="PHPCompatibilityWP"/>
2626

27+
<!-- Use the VIP Go ruleset. -->
28+
<rule ref="WordPress-VIP-Go" />
29+
30+
<!-- Use the WordPress.com VIP ruleset. -->
31+
<rule ref="WordPressVIPMinimum" />
32+
2733
<!-- For help in understanding this testVersion:
2834
https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
2935
<config name="testVersion" value="5.3-"/>

Diff for: composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"slowprog/composer-copy-file": "0.2.1",
1818
"wp-coding-standards/wpcs": "*",
1919
"xwp/wp-dev-lib": "^1.6.5"
20+
"automattic/vipwpcs": "^2.0"
2021
},
2122
"scripts": {
2223
"phpcs": [

Diff for: wp-includes/rest-api/auth/class-wp-rest-key-pair.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ public function register_routes() {
9696
'callback' => array( $this, 'generate_key_pair' ),
9797
'permission_callback' => '__return_true',
9898
'args' => array(
99-
'name' => array(
99+
'name' => array(
100100
'description' => esc_html__( 'The name of the key-pair.', 'jwt-auth' ),
101101
'type' => 'string',
102102
'required' => true,
103103
'sanitize_callback' => 'sanitize_text_field',
104104
'validate_callback' => 'rest_validate_request_arg',
105105
),
106-
'user_id' => array(
106+
'user_id' => array(
107107
'description' => esc_html__( 'The ID of the user.', 'jwt-auth' ),
108108
'type' => 'integer',
109109
'required' => true,
@@ -120,7 +120,7 @@ public function register_routes() {
120120
'callback' => array( $this, 'delete_all_key_pairs' ),
121121
'permission_callback' => '__return_true',
122122
'args' => array(
123-
'user_id' => array(
123+
'user_id' => array(
124124
'description' => esc_html__( 'The ID of the user.', 'jwt-auth' ),
125125
'type' => 'integer',
126126
'required' => true,
@@ -136,14 +136,14 @@ public function register_routes() {
136136
'callback' => array( $this, 'delete_key_pair' ),
137137
'permission_callback' => '__return_true',
138138
'args' => array(
139-
'user_id' => array(
139+
'user_id' => array(
140140
'description' => esc_html__( 'The ID of the user.', 'jwt-auth' ),
141141
'type' => 'integer',
142142
'required' => true,
143143
'sanitize_callback' => 'absint',
144144
'validate_callback' => 'rest_validate_request_arg',
145145
),
146-
'api_key' => array(
146+
'api_key' => array(
147147
'description' => esc_html__( 'The API key being revoked.', 'jwt-auth' ),
148148
'type' => 'string',
149149
'required' => true,
@@ -359,11 +359,14 @@ public function authenticate( $user, WP_REST_Request $request ) {
359359

360360
$found = false;
361361
$keypairs = $this->get_user_key_pairs( $get_user->ID );
362+
363+
// Update the "Last IP" which accessed the keypair. This may not work
364+
// in some environments due to caching.
362365
foreach ( $keypairs as $_key => $item ) {
363366
if ( isset( $item['api_key'] ) && $item['api_key'] === $key ) {
364367
$keypairs[ $_key ]['last_used'] = time();
365368

366-
$ip = isset( $_SERVER['REMOTE_ADDR'] ) ? filter_var( wp_unslash( $_SERVER['REMOTE_ADDR'] ), FILTER_VALIDATE_IP ) : null;
369+
$ip = isset( $_SERVER['REMOTE_ADDR'] ) ? filter_var( wp_unslash( $_SERVER['REMOTE_ADDR'] ), FILTER_VALIDATE_IP ) : null; // phpcs:ignore WordPressVIPMinimum.Variables.ServerVariables.UserControlledHeaders, WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___SERVER__REMOTE_ADDR__
367370
if ( $ip ) {
368371
$keypairs[ $_key ]['last_ip'] = $ip;
369372
}
@@ -708,6 +711,7 @@ public function template_new_key_pair() {
708711
* @since 0.1
709712
*/
710713
public function template_new_token_key_pair() {
714+
// phpcs:disable WordPressVIPMinimum.Security.Mustache.OutputNotation
711715
?>
712716
<script type="text/html" id="tmpl-new-token-key-pair">
713717
<div class="new-key-pair notification-dialog-wrap" data-api_key="{{ data.api_key }}" data-name="{{ data.name }}">
@@ -764,6 +768,7 @@ public function template_new_token_key_pair() {
764768
</div>
765769
</script>
766770
<?php
771+
// phpcs:enable WordPressVIPMinimum.Security.Mustache.OutputNotation
767772
}
768773

769774
/**

Diff for: wp-includes/rest-api/auth/class-wp-rest-token.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ public function register_routes() {
109109
'callback' => array( $this, 'generate_token' ),
110110
'permission_callback' => '__return_true',
111111
'args' => array(
112-
'api_key' => array(
112+
'api_key' => array(
113113
'description' => __( 'The API key of the user; requires also setting the api_secret.', 'jwt-auth' ),
114114
'type' => 'string',
115115
'sanitize_callback' => 'sanitize_text_field',
116116
'validate_callback' => 'rest_validate_request_arg',
117117
),
118-
'api_secret' => array(
118+
'api_secret' => array(
119119
'description' => __( 'The API secret of the user; requires also setting the api_key.', 'jwt-auth' ),
120120
'type' => 'string',
121121
'sanitize_callback' => 'sanitize_text_field',
@@ -346,7 +346,7 @@ public function authenticate_refresh_token( $user, WP_REST_Request $request ) {
346346
if ( isset( $item['api_key'] ) && $item['api_key'] === $token->data->user->api_key ) {
347347
$keypairs[ $_key ]['last_used'] = time();
348348

349-
$ip = isset( $_SERVER['REMOTE_ADDR'] ) ? filter_var( wp_unslash( $_SERVER['REMOTE_ADDR'] ), FILTER_VALIDATE_IP ) : null;
349+
$ip = isset( $_SERVER['REMOTE_ADDR'] ) ? filter_var( wp_unslash( $_SERVER['REMOTE_ADDR'] ), FILTER_VALIDATE_IP ) : null; // phpcs:ignore WordPressVIPMinimum.Variables.ServerVariables.UserControlledHeaders, WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___SERVER__REMOTE_ADDR__
350350
if ( $ip ) {
351351
$keypairs[ $_key ]['last_ip'] = $ip;
352352
}

0 commit comments

Comments
 (0)