Skip to content

Commit

Permalink
Add check for valid "method" tag
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianfabian committed Oct 27, 2023
1 parent abd7df9 commit 267cb6a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions nostr-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,18 @@ function validate_authorization_header() {

// check if hash matches payload tag
$didHaveValidU = false;
$didHaveValidMethod = false;
// $didHaveValidPayload = false; πŸ€·β€β™‚οΈπŸ€·β€β™‚οΈπŸ€·β€β™‚οΈ
foreach (array_values($json["tags"]) as $tag => $value) {
switch ($value[0]) {
case "method":
if ($value[1] == "POST") {
$didHaveValidMethod = true;
}
else {
return ["valid" => false, "message" => "Invalid \"method\" tag"];
}
break;
case "u":
$base_url = get_site_url();
$api_url = $base_url . '/wp-json/nostrmedia/v1/upload/';
Expand All @@ -128,8 +137,8 @@ function validate_authorization_header() {
}
}

if (!$didHaveValidU) {
// if (!$didHaveValidU || !$didHaveValidPayload) { πŸ€·β€β™‚οΈπŸ€·β€β™‚οΈπŸ€·β€β™‚οΈ
if (!$didHaveValidU || !$didHaveValidMethod) {
// if (!$didHaveValidU || !$didHaveValidMethod || !$didHaveValidPayload) { πŸ€·β€β™‚οΈπŸ€·β€β™‚οΈπŸ€·β€β™‚οΈ
return ["valid" => false, "message" => "Missing \"u\" or \"payload\" tag"];
}

Expand Down

0 comments on commit 267cb6a

Please sign in to comment.