diff --git a/docs/NEWS b/docs/NEWS
index 23d5fe62..e64f1bf2 100644
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,14 @@
Version 1.1 ()
------------------------------------------------------------------------
+ * Added functionality to reply to comments in the admin interface
+ (garvinhicking)
+
+ * Enhance spamblock plugin with session hash check, to prevent
+ automatted comment posting. Also prevents possible CSRF for
+ tricking you into submitting comments to your own blog. Thanks
+ to Stefan Esser! (garvinhicking)
+
* Support to delete multiple entries at once via checkboxes in the
entry admin panel, fix admin entry pagination to not show
next pages, if that next page were empty. (garvinhicking)
diff --git a/include/admin/comments.inc.php b/include/admin/comments.inc.php
index ef0e43d4..44f10ccd 100644
--- a/include/admin/comments.inc.php
+++ b/include/admin/comments.inc.php
@@ -13,7 +13,7 @@ if (!serendipity_checkPermission('adminComments')) {
$commentsPerPage = (int)(!empty($serendipity['GET']['filter']['perpage']) ? $serendipity['GET']['filter']['perpage'] : 10);
$summaryLength = 200;
-if ( $serendipity['POST']['formAction'] == 'multiDelete' && sizeof($serendipity['POST']['delete']) != 0 && serendipity_checkFormToken()) {
+if ($serendipity['POST']['formAction'] == 'multiDelete' && sizeof($serendipity['POST']['delete']) != 0 && serendipity_checkFormToken()) {
foreach ( $serendipity['POST']['delete'] as $k => $v ) {
serendipity_deleteComment($k, $v);
echo DONE . ': '. sprintf(COMMENT_DELETED, $k) . '
';
@@ -22,7 +22,7 @@ if ( $serendipity['POST']['formAction'] == 'multiDelete' && sizeof($serendipity[
/* We are asked to save the edited comment, and we are not in preview mode */
-if ( isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'doEdit' && !isset($serendipity['POST']['preview']) && serendipity_checkFormToken()) {
+if (isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'doEdit' && !isset($serendipity['POST']['preview']) && serendipity_checkFormToken()) {
$sql = "UPDATE {$serendipity['dbPrefix']}comments
SET
author = '" . serendipity_db_escape_string($serendipity['POST']['name']) . "',
@@ -36,9 +36,32 @@ if ( isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminActi
echo COMMENT_EDITED;
}
+/* Submit a new comment */
+if (isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'doReply' && !isset($serendipity['POST']['preview']) && serendipity_checkFormToken()) {
+ $comment = array();
+ $comment['url'] = $serendipity['POST']['url'];
+ $comment['comment'] = trim($serendipity['POST']['comment']);
+ $comment['name'] = $serendipity['POST']['name'];
+ $comment['email'] = $serendipity['POST']['email'];
+ $comment['subscribe'] = $serendipity['POST']['subscribe'];
+ $comment['parent_id'] = $serendipity['POST']['replyTo'];
+ if (!empty($comment['comment'])) {
+ if (serendipity_saveComment($serendipity['POST']['entry_id'], $comment, 'NORMAL')) {
+ echo '';
+ echo '';
+ return true;
+ } else {
+ echo COMMENT_NOT_ADDED;
+ $serendipity['GET']['adminAction'] = 'reply';
+ }
+ } else {
+ echo COMMENT_NOT_ADDED;
+ $serendipity['GET']['adminAction'] = 'reply';
+ }
+}
/* We approve a comment */
-if ( isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'approve' && serendipity_checkFormToken()) {
+if (isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'approve' && serendipity_checkFormToken()) {
$sql = "SELECT c.*, e.title, a.email as authoremail, a.mail_comments
FROM {$serendipity['dbPrefix']}comments c
LEFT JOIN {$serendipity['dbPrefix']}entries e ON (e.id = c.entry_id)
@@ -47,58 +70,89 @@ if ( isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminActi
$rs = serendipity_db_query($sql, true);
if ($rs === false) {
- echo ERROR .': '. sprintf(COMMENT_ALREADY_APPROVED, $serendipity['GET']['id']);
+ echo ERROR .': '. sprintf(COMMENT_ALREADY_APPROVED, (int)$serendipity['GET']['id']);
} else {
serendipity_approveComment($serendipity['GET']['id'], $rs['entry_id']);
- echo DONE . ': '. sprintf(COMMENT_APPROVED, $serendipity['GET']['id']);
+ echo DONE . ': '. sprintf(COMMENT_APPROVED, (int)$serendipity['GET']['id']);
}
}
/* We are asked to delete a comment */
-if ( isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'delete' && serendipity_checkFormToken()) {
+if (isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'delete' && serendipity_checkFormToken()) {
serendipity_deleteComment($serendipity['GET']['id'], $serendipity['GET']['entry_id']);
- echo DONE . ': '. sprintf(COMMENT_DELETED, $serendipity['GET']['id']);
+ echo DONE . ': '. sprintf(COMMENT_DELETED, (int)$serendipity['GET']['id']);
}
/* We are either in edit mode, or preview mode */
-if ( isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'edit' || isset($serendipity['POST']['preview'])) {
+if (isset($serendipity['GET']['adminAction']) && ($serendipity['GET']['adminAction'] == 'edit' || $serendipity['GET']['adminAction'] == 'reply') || isset($serendipity['POST']['preview'])) {
$serendipity['smarty_raw_mode'] = true; // Force output of Smarty stuff in the backend
serendipity_smarty_init();
- /* If we are not in preview, we need data from our database */
- if (!isset($serendipity['POST']['preview']) ) {
- $comment = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}comments WHERE id = ". (int)$serendipity['GET']['id']);
- $data['name'] = $comment[0]['author'];
- $data['email'] = $comment[0]['email'];
- $data['url'] = $comment[0]['url'];
- $data['replyTo'] = $comment[0]['parent_id'];
- $data['comment'] = $comment[0]['body'];
+ if ($serendipity['GET']['adminAction'] == 'reply' || $serendipity['GET']['adminAction'] == 'doReply') {
+ $c = serendipity_fetchComments($serendipity['GET']['entry_id'], 1, 'co.id', false, 'NORMAL', ' AND co.id=' . (int)$serendipity['GET']['id']);
- /* If we are in preview, we get data from our form */
- } elseif ( isset($serendipity['POST']['preview']) ) {
- $data['name'] = $serendipity['POST']['name'];
- $data['email'] = $serendipity['POST']['email'];
- $data['url'] = $serendipity['POST']['url'];
- $data['replyTo'] = $serendipity['POST']['replyTo'];
- $data['comment'] = $serendipity['POST']['comment'];
- $pc_data = array(
- array(
- 'email' => $serendipity['POST']['email'],
- 'author' => $serendipity['POST']['name'],
- 'body' => $serendipity['POST']['comment'],
- 'url' => $serendipity['POST']['url'],
- 'timestamp' => time()
- )
- );
-
- serendipity_printComments($pc_data);
+ if (isset($serendipity['POST']['preview'])) {
+ $c[] = array(
+ 'email' => $serendipity['POST']['email'],
+ 'author' => $serendipity['POST']['name'],
+ 'body' => $serendipity['POST']['comment'],
+ 'url' => $serendipity['POST']['url'],
+ 'timestamp' => time(),
+ 'parent_id' => $serendipity['GET']['id']
+ );
+ }
+
+ $target_url = '?serendipity[action]=admin&serendipity[adminModule]=comments&serendipity[adminAction]=doReply&serendipity[id]=' . (int)$serendipity['GET']['id'] . '&serendipity[entry_id]=' . (int)$serendipity['GET']['entry_id'] . '&serendipity[noBanner]=true&serendipity[noSidebar]=true&' . serendipity_setFormToken('url');
+ $data = $serendipity['POST'];
+ $data['replyTo'] = (int)$serendipity['GET']['id'];
+ $out = serendipity_printComments($c);
$serendipity['smarty']->display(serendipity_getTemplateFile('comments.tpl', 'serendipityPath'));
+
+ if (!isset($data['name'])) {
+ $data['name'] = $serendipity['serendipityRealname'];
+ }
+
+ if (!isset($data['email'])) {
+ $data['email'] = $serendipity['serendipityEmail'];
+ }
+ } else {
+ $target_url = '?serendipity[action]=admin&serendipity[adminModule]=comments&serendipity[adminAction]=doEdit&serendipity[id]=' . (int)$serendipity['GET']['id'] . '&serendipity[entry_id]=' . (int)$serendipity['GET']['entry_id'] . '&' . serendipity_setFormToken('url');
+
+ /* If we are not in preview, we need data from our database */
+ if (!isset($serendipity['POST']['preview'])) {
+ $comment = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}comments WHERE id = ". (int)$serendipity['GET']['id']);
+ $data['name'] = $comment[0]['author'];
+ $data['email'] = $comment[0]['email'];
+ $data['url'] = $comment[0]['url'];
+ $data['replyTo'] = $comment[0]['parent_id'];
+ $data['comment'] = $comment[0]['body'];
+
+ /* If we are in preview, we get data from our form */
+ } elseif (isset($serendipity['POST']['preview'])) {
+ $data['name'] = $serendipity['POST']['name'];
+ $data['email'] = $serendipity['POST']['email'];
+ $data['url'] = $serendipity['POST']['url'];
+ $data['replyTo'] = $serendipity['POST']['replyTo'];
+ $data['comment'] = $serendipity['POST']['comment'];
+ $pc_data = array(
+ array(
+ 'email' => $serendipity['POST']['email'],
+ 'author' => $serendipity['POST']['name'],
+ 'body' => $serendipity['POST']['comment'],
+ 'url' => $serendipity['POST']['url'],
+ 'timestamp' => time()
+ )
+ );
+
+ serendipity_printComments($pc_data);
+ $serendipity['smarty']->display(serendipity_getTemplateFile('comments.tpl', 'serendipityPath'));
+ }
}
serendipity_displayCommentForm(
$serendipity['GET']['entry_id'],
- '?serendipity[action]=admin&serendipity[adminModule]=comments&serendipity[adminAction]=doEdit&serendipity[id]=' . $serendipity['GET']['id'] . '&serendipity[entry_id]=' . $serendipity['GET']['entry_id'] . '&' . serendipity_setFormToken('url'),
+ $target_url,
NULL,
$data,
false,
@@ -407,6 +461,7 @@ foreach ($sql as $rs) {
")' title="" class="serendipityIconLink">
+
diff --git a/include/functions_config.inc.php b/include/functions_config.inc.php
index d58c860f..f8ec76d6 100644
--- a/include/functions_config.inc.php
+++ b/include/functions_config.inc.php
@@ -1786,7 +1786,7 @@ function serendipity_reportXSRF($type = 0, $reset = true, $use_config = false) {
* @see serendipity_setFormToken()
* @return boolean Returns true, if XSRF attempt was found and the token was missing
*/
-function serendipity_checkFormToken() {
+function serendipity_checkFormToken($output = true) {
global $serendipity;
$token = '';
@@ -1797,13 +1797,13 @@ function serendipity_checkFormToken() {
}
if (empty($token)) {
- echo serendipity_reportXSRF('token', false);
+ if ($output) echo serendipity_reportXSRF('token', false);
return false;
}
if ($token != md5(session_id()) &&
$token != md5($serendipity['COOKIE']['old_session'])) {
- echo serendipity_reportXSRF('token', false);
+ if ($output) echo serendipity_reportXSRF('token', false);
return false;
}
diff --git a/plugins/serendipity_event_spamblock/UTF-8/lang_de.inc.php b/plugins/serendipity_event_spamblock/UTF-8/lang_de.inc.php
index 18773405..eefd209c 100644
--- a/plugins/serendipity_event_spamblock/UTF-8/lang_de.inc.php
+++ b/plugins/serendipity_event_spamblock/UTF-8/lang_de.inc.php
@@ -99,3 +99,7 @@
@define('PLUGIN_EVENT_SPAMBLOCK_FORCEMODERATIONT_TREAT', 'Was soll mit auto-moderierten Trackbacks passieren?');
@define('PLUGIN_EVENT_SPAMBLOCK_FORCEMODERATIONT', 'Trackbackmoderation nach wievielen Tagen erzwingen');
@define('PLUGIN_EVENT_SPAMBLOCK_FORCEMODERATIONT_DESC', 'Alle Trackbacks zu einem Artikel können abhängig vom Alter des Artikels automatisch moderiert werden. Tragen Sie hier das Minimalalter eines Artikels in Tagen ein, ab dem jedes Trackback erst nach Ihrer Moderation dargestellt wird. 0 bedeutet, dass keine automatische Moderation erzeugt wird.');
+
+@define('PLUGIN_EVENT_SPAMBLOCK_CSRF', 'CSRF-Schutz aktivieren?');
+@define('PLUGIN_EVENT_SPAMBLOCK_CSRF_DESC', 'Falls aktiviert, wird ein spezieller Hash-Wert sicherstellen, dass nur Benutzer Kommentare hinterlassen dürfen , die eine gültige Session-ID haben. Dies wird Spam etwas eindämmen und es unmöglich machen, dass Sie ungewollt Kommentare via CSRF-Angriffen hinterlassen, aber es wird auch dazu führen dass nur Benutzer mit aktivierten Cookies kommentieren können.');
+@define('PLUGIN_EVENT_SPAMBLOCK_CSRF_REASON', 'Ihr Kommentar enthielt keinen gültigen Session-Hash. Kommentare auf diesem Blog können nur mit aktivierten Cookies hinterlassen werden!');
\ No newline at end of file
diff --git a/plugins/serendipity_event_spamblock/lang_de.inc.php b/plugins/serendipity_event_spamblock/lang_de.inc.php
index ebeb7825..05a3aed5 100644
--- a/plugins/serendipity_event_spamblock/lang_de.inc.php
+++ b/plugins/serendipity_event_spamblock/lang_de.inc.php
@@ -100,3 +100,8 @@
@define('PLUGIN_EVENT_SPAMBLOCK_FORCEMODERATIONT_TREAT', 'Was soll mit auto-moderierten Trackbacks passieren?');
@define('PLUGIN_EVENT_SPAMBLOCK_FORCEMODERATIONT', 'Trackbackmoderation nach wievielen Tagen erzwingen');
@define('PLUGIN_EVENT_SPAMBLOCK_FORCEMODERATIONT_DESC', 'Alle Trackbacks zu einem Artikel können abhängig vom Alter des Artikels automatisch moderiert werden. Tragen Sie hier das Minimalalter eines Artikels in Tagen ein, ab dem jedes Trackback erst nach Ihrer Moderation dargestellt wird. 0 bedeutet, dass keine automatische Moderation erzeugt wird.');
+
+@define('PLUGIN_EVENT_SPAMBLOCK_CSRF', 'CSRF-Schutz aktivieren?');
+@define('PLUGIN_EVENT_SPAMBLOCK_CSRF_DESC', 'Falls aktiviert, wird ein spezieller Hash-Wert sicherstellen, dass nur Benutzer Kommentare hinterlassen dürfen , die eine gültige Session-ID haben. Dies wird Spam etwas eindämmen und es unmöglich machen, dass Sie ungewollt Kommentare via CSRF-Angriffen hinterlassen, aber es wird auch dazu führen dass nur Benutzer mit aktivierten Cookies kommentieren können.');
+
+@define('PLUGIN_EVENT_SPAMBLOCK_CSRF_REASON', 'Ihr Kommentar enthielt keinen gültigen Session-Hash. Kommentare auf diesem Blog können nur mit aktivierten Cookies hinterlassen werden!');
\ No newline at end of file
diff --git a/plugins/serendipity_event_spamblock/lang_en.inc.php b/plugins/serendipity_event_spamblock/lang_en.inc.php
index 4d58f3c1..a94ff470 100644
--- a/plugins/serendipity_event_spamblock/lang_en.inc.php
+++ b/plugins/serendipity_event_spamblock/lang_en.inc.php
@@ -110,3 +110,7 @@
@define('PLUGIN_EVENT_SPAMBLOCK_FORCEMODERATIONT_TREAT', 'What to do with trackbacks when being auto-moderated?');
@define('PLUGIN_EVENT_SPAMBLOCK_FORCEMODERATIONT', 'Force trackback moderation after how many days');
@define('PLUGIN_EVENT_SPAMBLOCK_FORCEMODERATIONT_DESC', 'You can automatically set all trackbacks for entries to be moderated. Enter the age of an entry in days, after which it should be auto-moderated. 0 means no auto-moderation.');
+
+@define('PLUGIN_EVENT_SPAMBLOCK_CSRF', 'Use CSRF protection for comments?');
+@define('PLUGIN_EVENT_SPAMBLOCK_CSRF_DESC', 'If enabled, a special hash value will check that only users can submit a comment with a valid session ID. This will decrease spam and prevent users from tricking you into submitting comments via CSRF, but it will also prevent users commenting on your blog without cookies.');
+@define('PLUGIN_EVENT_SPAMBLOCK_CSRF_REASON', 'Your comment did not contain a Session-Hash. Comments can only be made on this blog when having cookies enabled!');
\ No newline at end of file
diff --git a/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php b/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php
index 5b963910..ebc6c731 100644
--- a/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php
+++ b/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php
@@ -34,7 +34,7 @@ var $filter_defaults;
'smarty' => '2.6.7',
'php' => '4.1.0'
));
- $propbag->add('version', '1.53');
+ $propbag->add('version', '1.60');
$propbag->add('event_hooks', array(
'frontend_saveComment' => true,
'external_plugin' => true,
@@ -49,6 +49,7 @@ var $filter_defaults;
'bodyclone',
'entrytitle',
'ipflood',
+ 'csrf',
'captchas',
'captchas_ttl',
'captcha_color',
@@ -113,6 +114,13 @@ var $filter_defaults;
$propbag->add('default', false);
break;
+ case 'csrf':
+ $propbag->add('type', 'boolean');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_CSRF);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_CSRF_DESC);
+ $propbag->add('default', true);
+ break;
+
case 'entrytitle':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_FILTER_TITLE);
@@ -596,6 +604,15 @@ var $filter_defaults;
$logfile = $this->logfile = $this->get_config('logfile', $serendipity['serendipityPath'] . 'spamblock.log');
$required_fields = $this->get_config('required_fields', '');
+ // Check CSRF [comments only, cannot be applied to trackbacks]
+ if ($addData['type'] == 'NORMAL' && serendipity_db_bool($this->get_config('csrf', true))) {
+ if (!serendipity_checkFormToken(false)) {
+ $this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_CSRF_REASON, $addData);
+ $eventData = array('allow_comments' => false);
+ $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_CSRF_REASON;
+ }
+ }
+
// Check required fields
if ($addData['type'] == 'NORMAL' && !empty($required_fields)) {
$required_field_list = explode(',', $required_fields);
@@ -905,6 +922,10 @@ var $filter_defaults;
echo '
@@ -104,6 +105,7 @@ if (serendipity_is_iframe()) { | |
+ |