fix possible CSRF attack by setting document name

This commit is contained in:
Uwe Steinmann 2021-06-14 09:09:36 +02:00
parent dfb6061b41
commit ab546099f1
4 changed files with 23 additions and 19 deletions

View File

@ -614,29 +614,34 @@ switch($command) {
break; /* }}} */
case 'setdocumentname': /* {{{ */
if(1||$user) {
$document = $dms->getDocument($_REQUEST['id']);
if($document) {
if ($document->getAccessMode($user) >= M_READWRITE) {
$oldname = $document->getName();
if (!$document->setName($_REQUEST['name'])) {
header('Content-Type: application/json');
echo json_encode(array('success'=>false, 'message'=>'Error setting name', 'data'=>''));
} else {
if($notifier) {
$notifier->sendChangedNameMail($document, $user, $oldname);
if($user) {
if(checkFormKey('setdocumentname')) {
$document = $dms->getDocument($_REQUEST['id']);
if($document) {
if ($document->getAccessMode($user) >= M_READWRITE) {
$oldname = $document->getName();
if (!$document->setName($_REQUEST['name'])) {
header('Content-Type: application/json');
echo json_encode(array('success'=>false, 'message'=>'Error setting name', 'data'=>''));
} else {
if($notifier) {
$notifier->sendChangedNameMail($document, $user, $oldname);
}
header('Content-Type: application/json');
echo json_encode(array('success'=>true, 'message'=>getMLText('splash_document_name_changed'), 'data'=>''));
add_log_line();
}
} else {
header('Content-Type: application/json');
echo json_encode(array('success'=>true, 'message'=>getMLText('splash_document_name_changed'), 'data'=>''));
add_log_line();
echo json_encode(array('success'=>false, 'message'=>getMLText('access_denied'), 'data'=>''));
}
} else {
header('Content-Type: application/json');
echo json_encode(array('success'=>false, 'message'=>getMLText('access_denied'), 'data'=>''));
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_doc_id'), 'data'=>''));
}
} else {
header('Content-Type: application/json');
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_doc_id'), 'data'=>''));
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_request_token'), 'data'=>''));
}
}
break; /* }}} */

View File

@ -2307,7 +2307,7 @@ $(function() {
if(!empty($this->params['settings']->_inlineEditing)) {
echo "<span class=\"editable\" contenteditable=\"true\"";
if($object->isType('document'))
echo " data-document=\"".$object->getId()."\"";
echo " data-document=\"".$object->getId()."\" data-formtoken=\"".createFormKey('setdocumentname')."\"";
echo ">".$text;
echo "</span>\n";
} else

View File

@ -2348,7 +2348,7 @@ $(function() {
if(!empty($this->params['settings']->_inlineEditing)) {
echo "<span class=\"editable\" contenteditable=\"true\"";
if($object->isType('document'))
echo " data-document=\"".$object->getId()."\"";
echo " data-document=\"".$object->getId()."\" data-formtoken=\"".createFormKey('setdocumentname')."\"";
echo ">".$text;
echo "</span>\n";
} else

View File

@ -617,9 +617,8 @@ $(document).ready( function() {
$("body").on("blur", "span.editable", function(e) { /* {{{ */
console.log($(this).data('document'));
console.log('Hallo'+$(this).text());
e.preventDefault();
$.post( "../op/op.Ajax.php", { command: "setdocumentname", id: $(this).data('document'), name: $(this).text() })
$.post( "../op/op.Ajax.php", { command: "setdocumentname", id: $(this).data('document'), formtoken: $(this).data('formtoken'), name: $(this).text() })
.done(function( data ) {
noty({
text: data.message,