Answer the question
In order to leave comments, you need to log in
How to verify the authenticity of data received from VKontakte?
VK recently launched Community Apps . Regular iframe, get-parameters with user id are passed to the iframe address, and other info...
For security, I need to make sure that these get-parameters are not faked by the user. The documentation seems to have a solution for this:
Among the launch parameters, sign is passed - the signature of the request. With it, you can make sure that the request data has not been spoofed on the client side.
PHP code example for request signature verification:
$sign = ""; foreach ($request->getParams() as $key => $param) { if ($key == 'hash' || $key == 'sign') continue; $sign .=$param; } $secret = 'SECRET_KEY'; $sig = $secret ? hash_hmac('sha256', $sign, $secret) : "";
$sign = '';
foreach ($this->input->get() as $key => $value)
{
if ($key == 'hash' || $key == 'sign') continue;
$sign .= $value;
}
$secret = 's91kf39194ksk141jSdsj1';
$sig = $secret ? hash_hmac('sha256', $sign, $secret) : '';
echo $sig == $this->input->get('sign');
Answer the question
In order to leave comments, you need to log in
There are 2 options:
1) The parameters are processed in the wrong order (for example, you are processing sorted values)
2) A new parameter was added to the script along the way from VK, for example, from rewrite_module.
In general, show on the screen what happened in $sig , $key , $value show. Maybe they are empty. In short, debug
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question