diff --git a/publish/write.inc.php b/publish/write.inc.php index b725bad..9310942 100644 --- a/publish/write.inc.php +++ b/publish/write.inc.php @@ -4,7 +4,8 @@ $search = get_search_args(); if ($action == 'preview') $result = get_post_data(TRUE); -else if ($action && is_numeric($id)) +// Only editors load a saved story; it holds the author's email address +else if ($is_admin && $action && is_numeric($id)) $result = get_query($id); if (isset($result) && is_array($result)) extract($result[0], EXTR_OVERWRITE); diff --git a/tests/php/Pages/SubmitTest.php b/tests/php/Pages/SubmitTest.php index 99e5810..b3fe4fe 100644 --- a/tests/php/Pages/SubmitTest.php +++ b/tests/php/Pages/SubmitTest.php @@ -97,6 +97,17 @@ class SubmitTest extends PageTestCase { $this->assertSame(array('original author', 0, ''), array($tables['queue'][0]['editor'], $tables['queue'][0]['hidden'], $tables['queue'][0]['comments'])); } + public function testVisitorsCannotLoadAStoryIntoTheForm(): void { + $this->setTables(array('xxx' => array(array('id' => 7, 'title' => 'Live one', 'email' => 'author@example.org')))); + $token = $this->csrfToken($this->get('/publish')['body']); + foreach (array('edit', 'choose', 'other') as $action) { + $page = $this->post('/publish', array('action' => $action, 'id' => '7', 'csrf_token' => $token)); + $this->assertStringNotContainsString('author@example.org', $page['body']); + $this->assertStringNotContainsString('Live one', $page['body']); + } + $this->assertSame(array(), $this->queries('/^SELECT \* FROM xxx/')); + } + public function testAPostWithoutTheTokenOnlyGetsAPreview(): void { $this->get('/publish'); $page = $this->post('/publish', $this->story(array('action' => 'submit', 'csrf_token' => 'wrong', 'g-recaptcha-response' => 'pass')));