Skip to content

Commit d186bd4

Browse files
committed
add isValidMeta for ajax Csrf control
1 parent 0651346 commit d186bd4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Ubiquity/security/csrf/UCsrfHttp.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Ubiquity\security\csrf;
33

44
use Ubiquity\utils\http\UCookie;
5+
use Ubiquity\controllers\Startup;
56

67
/**
78
* Ubiquity\security\csrf$UCsrfHttp
@@ -45,6 +46,19 @@ public static function isValidCookie(string $name): bool {
4546
}
4647
return false;
4748
}
49+
50+
/**
51+
* Returns whether the given CSRF token is present and valid in header meta csrf-token, given his name.
52+
* @param string $name
53+
* @return bool
54+
*/
55+
public static function isValidMeta(string $name):bool{
56+
$headers=Startup::getHttpInstance ()->getAllHeaders ();
57+
if(isset($headers['csrf-token'])){
58+
list($id,$value)=explode(':', $headers['csrf-token']);
59+
return $id===CsrfManager::getSelector($name) && CsrfManager::isValidByName($name, $value);
60+
}
61+
}
4862

4963
/**
5064
* Adds a token in headers.

0 commit comments

Comments
 (0)