-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from mashirozx/dev
add nonce check for api
- Loading branch information
Showing
5 changed files
with
21 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
/** | ||
* Image uploader response | ||
*/ | ||
function upload_image(WP_REST_Request $req) | ||
function upload_image(WP_REST_Request $request) | ||
{ | ||
// see: https://developer.wordpress.org/rest-api/requests/ | ||
|
||
|
@@ -28,8 +28,20 @@ function upload_image(WP_REST_Request $req) | |
* -F "[email protected]" \ | ||
* https://dev.2heng.xin/wp-json/sakura/v1/image/upload | ||
*/ | ||
// $file = $req->get_file_params(); | ||
|
||
// $file = $request->get_file_params(); | ||
if ( !check_ajax_referer('wp_rest', '_wpnonce', false) ) { | ||
$output = array( | ||
'status' => 403, | ||
'success' => false, | ||
'message' => 'Unauthorized client.', | ||
'link' => "https://view.moezx.cc/images/2019/11/14/step04.md.png", | ||
'proxy' => akina_option('cmt_image_proxy') . "https://view.moezx.cc/images/2019/11/14/step04.md.png", | ||
); | ||
$result = new WP_REST_Response($output, 403); | ||
$result->set_headers(array('Content-Type' => 'application/json')); | ||
return $result; | ||
} | ||
|
||
switch (akina_option("img_upload_api")) { | ||
case 'imgur': | ||
$image = file_get_contents($_FILES["cmt_img_file"]["tmp_name"]); | ||
|
@@ -254,4 +266,4 @@ function cache_search_json() | |
'Cache-Control' => 'max-age=3600')); // json 缓存控制 | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters