diff --git a/CHANGELOG.md b/CHANGELOG.md index b431b5b0..a3305cbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * ADDED: Input sanitation to some not yet filtered query and server parameters * CHANGED: "Send" button now labeled "Create" (#946) * CHANGED: drop some PHP < 5.6 fallbacks, minimum version is PHP 7.3 as of release 1.6.0 +* CHANGED: `create` attribute is no longer returned in API for pastes (#1290) * FIXED: Add cache control headers also to API calls (#1263) * FIXED: Shortened paste URL does not appear in email (#606) diff --git a/doc/Installation.md b/doc/Installation.md index 77f79fbb..06fb835c 100644 --- a/doc/Installation.md +++ b/doc/Installation.md @@ -169,14 +169,13 @@ user these additional privileges: For reference or if you want to create the table schema for yourself to avoid having to give PrivateBin too many permissions (replace `prefix_` with your own -table prefix and create the table schema with your favourite MariaDB/MySQL +table prefix and create the table schema with your favorite MariaDB/MySQL client): ```sql CREATE TABLE prefix_paste ( dataid CHAR(16) NOT NULL, data MEDIUMBLOB, - postdate INT, expiredate INT, opendiscussion INT, burnafterreading INT, diff --git a/lib/Data/Database.php b/lib/Data/Database.php index 27874962..20e98622 100644 --- a/lib/Data/Database.php +++ b/lib/Data/Database.php @@ -146,9 +146,6 @@ class Database extends AbstractData $attachment = $attachmentname = null; $meta = $paste['meta']; $isVersion1 = array_key_exists('data', $paste); - list($createdKey) = $this->_getVersionedKeys($isVersion1 ? 1 : 2); - $created = (int) $meta[$createdKey]; - unset($meta[$createdKey], $paste['meta']); if (array_key_exists('expire_date', $meta)) { $expire_date = (int) $meta['expire_date']; unset($meta['expire_date']); @@ -177,11 +174,10 @@ class Database extends AbstractData try { return $this->_exec( 'INSERT INTO "' . $this->_sanitizeIdentifier('paste') . - '" VALUES(?,?,?,?,?,?,?,?,?)', + '" VALUES(?,?,?,?,?,?,?,?)', array( $pasteid, $isVersion1 ? $paste['data'] : Json::encode($paste), - $created, $expire_date, (int) $opendiscussion, (int) $burnafterreading, @@ -218,13 +214,7 @@ class Database extends AbstractData // create array $data = Json::decode($row['data']); $isVersion2 = array_key_exists('v', $data) && $data['v'] >= 2; - if ($isVersion2) { - $paste = $data; - list($createdKey) = $this->_getVersionedKeys(2); - } else { - $paste = array('data' => $row['data']); - list($createdKey) = $this->_getVersionedKeys(1); - } + $paste = $isVersion2 ? $data : array('data' => $row['data']); try { $row['meta'] = Json::decode($row['meta']); @@ -233,7 +223,6 @@ class Database extends AbstractData } $row = self::upgradePreV1Format($row); $paste['meta'] = $row['meta']; - $paste['meta'][$createdKey] = (int) $row['postdate']; $expire_date = (int) $row['expiredate']; if ($expire_date > 0) { $paste['meta']['expire_date'] = $expire_date; @@ -751,7 +740,6 @@ class Database extends AbstractData 'CREATE TABLE "' . $this->_sanitizeIdentifier('paste') . '" ( ' . "\"dataid\" CHAR(16) NOT NULL$main_key, " . "\"data\" $attachmentType, " . - '"postdate" INT, ' . '"expiredate" INT, ' . '"opendiscussion" INT, ' . '"burnafterreading" INT, ' . @@ -926,6 +914,12 @@ class Database extends AbstractData ); } // no break, continue with updates for all newer versions + case '1.7.2': + $this->_db->exec( + 'ALTER TABLE "' . $this->_sanitizeIdentifier('paste') . + "\" DROP COLUMN \"postdate\"" + ); + // no break, continue with updates for all newer versions default: $this->_exec( 'UPDATE "' . $this->_sanitizeIdentifier('config') . diff --git a/lib/Model/Paste.php b/lib/Model/Paste.php index 8a529c84..c64f5c4f 100644 --- a/lib/Model/Paste.php +++ b/lib/Model/Paste.php @@ -37,7 +37,7 @@ class Paste extends AbstractModel throw new Exception(Controller::GENERIC_ERROR, 64); } - // check if paste has expired and delete it if neccessary. + // check if paste has expired and delete it if necessary. if (array_key_exists('expire_date', $data['meta'])) { if ($data['meta']['expire_date'] < time()) { $this->delete(); @@ -92,7 +92,6 @@ class Paste extends AbstractModel throw new Exception('You are unlucky. Try again.', 75); } - $this->_data['meta']['created'] = time(); $this->_data['meta']['salt'] = ServerSalt::generate(); // store paste diff --git a/tst/Bootstrap.php b/tst/Bootstrap.php index 7f4caa32..8ea249d2 100644 --- a/tst/Bootstrap.php +++ b/tst/Bootstrap.php @@ -508,6 +508,11 @@ class ConnectionInterfaceStub implements ConnectionInterface throw new BadMethodCallException('not supported by this stub'); } + public function restoreObject(array $args = array()) + { + throw new BadMethodCallException('not supported by this stub'); + } + public function copyObject(array $args = array()) { throw new BadMethodCallException('not supported by this stub'); @@ -655,7 +660,6 @@ class Helper ), 'meta' => array( 'expire' => '5min', - 'created' => 1344803344, ), 'v' => 2, 'ct' => 'ME5JF/YBEijp2uYMzLZozbKtWc5wfy6R59NBb7SmRig=', diff --git a/tst/ControllerTest.php b/tst/ControllerTest.php index 8aee7829..f0b87299 100644 --- a/tst/ControllerTest.php +++ b/tst/ControllerTest.php @@ -170,6 +170,7 @@ class ControllerTest extends TestCase $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertTrue($this->_data->exists($response['id']), 'paste exists after posting data'); $paste = $this->_data->read($response['id']); + $this->assertFalse(array_key_exists('created', $paste['meta']), 'does not output created'); $this->assertEquals( hash_hmac('sha256', $response['id'], $paste['meta']['salt']), $response['deletetoken'], @@ -712,7 +713,7 @@ class ControllerTest extends TestCase $this->assertEquals($paste['adata'][1], $response['adata'][1], 'outputs formatter correctly'); $this->assertEquals($paste['adata'][2], $response['adata'][2], 'outputs opendiscussion correctly'); $this->assertEquals($paste['adata'][3], $response['adata'][3], 'outputs burnafterreading correctly'); - $this->assertEquals($paste['meta']['created'], $response['meta']['created'], 'outputs created correctly'); + $this->assertFalse(array_key_exists('created', $paste['meta']), 'does not output created'); $this->assertEquals(0, $response['comment_count'], 'outputs comment_count correctly'); $this->assertEquals(0, $response['comment_offset'], 'outputs comment_offset correctly'); // by default it will be deleted instantly after it is read @@ -741,7 +742,7 @@ class ControllerTest extends TestCase $this->assertEquals($paste['adata'][1], $response['adata'][1], 'outputs formatter correctly'); $this->assertEquals($paste['adata'][2], $response['adata'][2], 'outputs opendiscussion correctly'); $this->assertEquals($paste['adata'][3], $response['adata'][3], 'outputs burnafterreading correctly'); - $this->assertEquals($paste['meta']['created'], $response['meta']['created'], 'outputs created correctly'); + $this->assertFalse(array_key_exists('created', $paste['meta']), 'does not output created'); $this->assertEquals(0, $response['comment_count'], 'outputs comment_count correctly'); $this->assertEquals(0, $response['comment_offset'], 'outputs comment_offset correctly'); } diff --git a/tst/Data/DatabaseTest.php b/tst/Data/DatabaseTest.php index 1c5b79de..c903e715 100644 --- a/tst/Data/DatabaseTest.php +++ b/tst/Data/DatabaseTest.php @@ -259,12 +259,11 @@ class DatabaseTest extends TestCase $this->_options['pwd'], $this->_options['opt'] ); - $statement = $db->prepare('INSERT INTO bar_paste VALUES(?,?,?,?,?,?,?,?,?)'); + $statement = $db->prepare('INSERT INTO bar_paste VALUES(?,?,?,?,?,?,?,?)'); $statement->execute( array( Helper::getPasteId(), $paste['data'], - $paste['meta']['postdate'], $paste['meta']['expire_date'], 0, 0, @@ -292,7 +291,7 @@ class DatabaseTest extends TestCase $this->_options['tbl'] = 'baz_'; $model = new Database($this->_options); $paste = Helper::getPaste(1, array('expire_date' => 1344803344)); - unset($paste['meta']['formatter'], $paste['meta']['opendiscussion'], $paste['meta']['salt']); + unset($paste['meta']['formatter'], $paste['meta']['opendiscussion'], $paste['meta']['postdate'], $paste['meta']['salt']); $model->delete(Helper::getPasteId()); $db = new PDO( @@ -301,12 +300,11 @@ class DatabaseTest extends TestCase $this->_options['pwd'], $this->_options['opt'] ); - $statement = $db->prepare('INSERT INTO baz_paste VALUES(?,?,?,?,?,?,?,?,?)'); + $statement = $db->prepare('INSERT INTO baz_paste VALUES(?,?,?,?,?,?,?,?)'); $statement->execute( array( Helper::getPasteId(), $paste['data'], - $paste['meta']['postdate'], $paste['meta']['expire_date'], 0, 0, diff --git a/tst/JsonApiTest.php b/tst/JsonApiTest.php index 032ff4d7..6de7f7bd 100644 --- a/tst/JsonApiTest.php +++ b/tst/JsonApiTest.php @@ -180,7 +180,7 @@ class JsonApiTest extends TestCase $this->assertEquals(Helper::getPasteId(), $response['id'], 'outputs data correctly'); $this->assertStringEndsWith('?' . $response['id'], $response['url'], 'returned URL points to new paste'); $this->assertEquals($paste['ct'], $response['ct'], 'outputs data correctly'); - $this->assertEquals($paste['meta']['created'], $response['meta']['created'], 'outputs postdate correctly'); + $this->assertFalse(array_key_exists('created', $paste['meta']), 'does not output created'); $this->assertEquals(0, $response['comment_count'], 'outputs comment_count correctly'); $this->assertEquals(0, $response['comment_offset'], 'outputs comment_offset correctly'); } diff --git a/tst/ModelTest.php b/tst/ModelTest.php index 03855405..de5d7118 100644 --- a/tst/ModelTest.php +++ b/tst/ModelTest.php @@ -134,12 +134,11 @@ class ModelTest extends TestCase $options['model_options']['pwd'], $options['model_options']['opt'] ); - $statement = $db->prepare('INSERT INTO paste VALUES(?,?,?,?,?,?,?,?,?)'); + $statement = $db->prepare('INSERT INTO paste VALUES(?,?,?,?,?,?,?,?)'); $statement->execute( array( Helper::getPasteId(), $pasteData['data'], - $pasteData['meta']['postdate'], 0, 0, 0,