Browse Source

rollback key format

main
ghost 10 months ago
parent
commit
a99d5e5be4
  1. 2
      .env
  2. 54
      src/Controller/RoomController.php

2
.env

@ -104,7 +104,7 @@ APP_ADD_POST_REMOTE_IP_DENIED=
# Post ID rules (for kevacoin key) # Post ID rules (for kevacoin key)
# do not change to keep external KevaChat nodes compatibility # do not change to keep external KevaChat nodes compatibility
APP_ADD_POST_KEY_REGEX=/^[A-z0-9-]{1,520}$/ APP_ADD_POST_KEY_REGEX=/^([\d]{1,260})@([A-z0-9-_]{1,260})$/
# Post content rules (for kevacoin value, max length is 3072) # Post content rules (for kevacoin value, max length is 3072)
# do not change to keep external KevaChat nodes compatibility # do not change to keep external KevaChat nodes compatibility

54
src/Controller/RoomController.php

@ -227,7 +227,7 @@ class RoomController extends AbstractController
} }
// Require valid kevachat meta // Require valid kevachat meta
if ($data = $this->_post($client, $pending)) if ($data = $this->_post($pending))
{ {
// Detect parent post // Detect parent post
preg_match(self::PARENT_REGEX, $data->message, $mention); preg_match(self::PARENT_REGEX, $data->message, $mention);
@ -260,7 +260,7 @@ class RoomController extends AbstractController
} }
// Require valid kevachat meta // Require valid kevachat meta
if ($data = $this->_post($client, $post)) if ($data = $this->_post($post))
{ {
// Detect parent post // Detect parent post
preg_match(self::PARENT_REGEX, $data->message, $mention); preg_match(self::PARENT_REGEX, $data->message, $mention);
@ -614,7 +614,11 @@ class RoomController extends AbstractController
if ( if (
$client->kevaPut( $client->kevaPut(
$request->get('namespace'), $request->get('namespace'),
$username, sprintf(
'%d@%s',
time(),
$username
),
$request->get('message') $request->get('message')
) )
) { ) {
@ -681,7 +685,11 @@ class RoomController extends AbstractController
); );
$pool->setKey( $pool->setKey(
sprintf(
'%d@%s',
time(),
$username $username
),
); );
$pool->setValue( $pool->setValue(
@ -731,7 +739,11 @@ class RoomController extends AbstractController
if ( if (
$client->kevaPut( $client->kevaPut(
$request->get('namespace'), $request->get('namespace'),
$username, sprintf(
'%d@%s',
time(),
$username
),
$request->get('message') $request->get('message')
) )
) )
@ -1092,10 +1104,7 @@ class RoomController extends AbstractController
); );
} }
private function _post( private function _post(array $data): ?object
\Kevachat\Kevacoin\Client $client,
array $data
): ?object
{ {
// Validate required data // Validate required data
if (empty($data['txid'])) if (empty($data['txid']))
@ -1113,23 +1122,8 @@ class RoomController extends AbstractController
return null; return null;
} }
// Skip values with meta keys
if (str_starts_with($data['key'], '_'))
{
return null;
}
// Legacy key format support (protocol v1 contain timestamp in prefix)
if (preg_match('/^([\d]+)@([A-z0-9\.\:\[\]]+)/', $data['key'], $matches))
{
if (!empty($matches[2]))
{
$data['key'] = $matches[2];
}
}
// Validate key format allowed in settings // Validate key format allowed in settings
if (!preg_match((string) $this->getParameter('app.add.post.key.regex'), $data['key'])) if (!preg_match((string) $this->getParameter('app.add.post.key.regex'), $data['key'], $key))
{ {
return null; return null;
} }
@ -1140,8 +1134,8 @@ class RoomController extends AbstractController
return null; return null;
} }
// Get time from raw transaction // Validate timestamp@username
if (!$transaction = $client->getRawTransaction($data['txid'])) if (empty($key[1]) || empty($key[2]))
{ {
return null; return null;
} }
@ -1155,9 +1149,9 @@ class RoomController extends AbstractController
return (object) return (object)
[ [
'id' => $data['txid'], 'id' => $data['txid'],
'user' => $data['key'], 'time' => $key[1],
'message' => $data['value'], 'user' => $key[2],
'time' => $transaction['time'] 'message' => $data['value']
]; ];
} }
@ -1224,7 +1218,7 @@ class RoomController extends AbstractController
foreach ($raw as $data) foreach ($raw as $data)
{ {
// Is valid post // Is valid post
if ($this->_post($client, $data)) if ($this->_post($data))
{ {
$total++; $total++;
} }

Loading…
Cancel
Save