Ticket #826 (closed defect: fixed)

Opened 4 years ago

Last modified 15 months ago

Enforcing max. length of edit note

Reported by: toringe Owned by: DotMG
Priority: normal Milestone: 1.3.1
Component: handlers Version: 1.1.6.5
Severity: minor Keywords: note, trunk-ported
Cc:

Description (last modified by DarTar) (diff)

Before 1.1.6.6 the maximum length of a page edit summary was not enforced in the form using maxlength. This did not cause major issues because the field was correctly truncated when storing a revision in the database.

The original reporter of this ticket experienced a major problem with edit notes. However, this does not appear to be a Wikka bug but a version-specific MySQL issue. See this discussion for further information and suggested workaround:  http://bugs.mysql.com/bug.php?id=18908. [1268] should help avoid issues of this kind.


The two input fields for notes in the edit.php file have a "size" attribute, but that doesn't prevent the user from typing more than 50 chars into the fields. (As defined by MAX_EDIT_NOTE_LENGTH)

If the user types a bit more than 50 chars in the note, then this results in: Query failed: SQL statement (Data too long for column 'note' at row 1)

This bug is worse than it seems: The page is also completely removed and most of the history is gone. This can be avoided by clicking on the back button in your browser and click on "store" again. Without a note, or a shorter note of course.

If you're using the wiki as a public wiki, then this can be abused by people who wants to wreck it, as the history is gone.

I've added an easy workaround to my own wiki: After the type="text" I've added maxlength="'.MAX_EDIT_NOTE_LENGTH.'" on both the input fields for notes. But I don't know if that takes care of the entire problem.

Preview:

if ($this->config['require_edit_note'] != 2) //check if edit_notes are enabled
		{
			$preview_buttons .= '<input size="'.MAX_EDIT_NOTE_LENGTH.'" type="text" maxlength="'.MAX_EDIT_NOTE_LENGTH.'" name="note" value="'.$this->hsc_secure($note).'" '.$highlight_note.'/>'.LABEL_EDIT_NOTE.'<br />'."\n";
		}

Store:

if ($this->config['require_edit_note'] != 2) //check if edit_notes are enabled
		{
			$output .= '<input size="'.MAX_EDIT_NOTE_LENGTH.'" type="text" maxlength="'.MAX_EDIT_NOTE_LENGTH.'" name="note" value="'.$this->hsc_secure($note).'" '.$highlight_note.'/> '.LABEL_EDIT_NOTE.'<br />'."\n";
		}

Change History

Changed 4 years ago by BrianKoontz

What version of MySQL are you using? As of 1.1.6.6 (not yet released), the "note" field is declared as a varchar(100). My testing (using MySQL 4.1) indicates that the field is being truncated properly, with no loss of data, error messages, etc. The MySQL documentation seems to confirm this behavior:

If you assign a value to a CHAR or VARCHAR column that exceeds the column's maximum length, the value is truncated to fit. If the truncated characters are not spaces, a warning is generated.

Changed 4 years ago by TormodHaugen

  • status changed from new to infoneeded_new

Changed 4 years ago by toringe

Server version: 5.0.67-community-nt

Info about the web server:

  • Apache/2.2.9 (Win32) PHP/5.2.6
  • MySQL client version: 5.0.51a
  • PHP extension: mysql

Sorry for the late reply. I thought I should reply to the mail.

Changed 3 years ago by BrianKoontz

  • status changed from infoneeded_new to new

I could not recreate the DB crash or loss of page history. However, it's probably prudent to enforce MAX_EDIT_NOTE_LENGTH (otherwise, why bother defining it?).

Changed 3 years ago by BrianKoontz

  • owner changed from unassigned to BrianKoontz
  • status changed from new to accepted

Changed 3 years ago by BrianKoontz

(In [1268]) Added maxlength attribute to notes field. Refs #826

Changed 3 years ago by BrianKoontz

  • status changed from accepted to testing

Changed 3 years ago by DarTar

  • keywords 1.1.7-unported added
  • component changed from editor to handlers

Changed 3 years ago by DarTar

  • summary changed from Too large notes crash the page and it's history. to Too large notes may crash a page and its history.

Changed 3 years ago by DarTar

toringe, I was also unable to reproduce this bug with PHP 5.2.6 / MySQL 5.0.51b. My Wikka instance behaves as expected (see Brian's first comment). I am afraid we need more research to understand what was causing the problem on your server.

If this issue is not reproducible, I suggest we apply the patch as in [1268] but change the wording of the ticket that suggests a major vulnerability so far unconfirmed.

Changed 3 years ago by toringe

We are testing now as we speak. The server administrator is trying to alter the MySQL configuration and test without the maxlenght property. So far it still crashing. Just had to test if it's the case for brand new pages too, and yes it is:

Query failed: insert into missions_pages set tag = 'TestPage', time = now(), owner = 'TorInge', user = 'TorInge', note = '1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890', latest = 'Y', body = 'Testpage' (Data too long for column 'note' at row 1)

Changed 3 years ago by DarTar

I just tested your query in MySQL on an unmodified Wikka table, everything works as expected (row stored with truncated string). Can you try to do the same (run a direct query in the DB) and report the result? Thanks.

mysql> \u wikka
Database changed
mysql> insert into 1165test_pages set tag = 'TestPage', time = now(), owner = 'TorInge', user = 'TorInge', note = '1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890', latest = 'Y', body = 'Testpage';
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> SHOW WARNINGS;
+---------+------+-------------------------------------------+
| Level   | Code | Message                                   |
+---------+------+-------------------------------------------+
| Warning | 1265 | Data truncated for column 'note' at row 1 | 
+---------+------+-------------------------------------------+
1 row in set (0.00 sec)

Changed 3 years ago by DarTar

After some research, it looks like you may have hit a version-specific MySQL bug. Take a look at this discussion:  http://bugs.mysql.com/bug.php?id=18908

Changed 3 years ago by toringe

I have notified the administrator about the bug. I hope we can sort this one out.

I tested the sql statement directly in phpmyadmin and got the same error:

#1406 - Data too long for column 'note' at row 1

Changed 3 years ago by DarTar

  • status changed from testing to commit
  • description modified (diff)
  • summary changed from Too large notes may crash a page and its history. to Enforcing max. length of edit note

I am changing the status and title of the ticket accordingly. This appears to be a low level MySQL issue, not a Wikka bug. The ticket now refers to the enforcement of the edit note length limit as defined in MAX_EDIT_NOTE_LENGTH, patched by Brian.

Changed 3 years ago by DarTar

  • status changed from commit to closed
  • resolution set to fixed
  • description modified (diff)
  • severity changed from normal to minor

tested, changing description

Changed 3 years ago by BrianKoontz

  • keywords trunk-unported added; note 1.1.7-unported removed

Changed 3 years ago by BrianKoontz

  • keywords note, added

Changed 3 years ago by BrianKoontz

(In [1338]) Ported to trunk. Refs #826.

Changed 3 years ago by BrianKoontz

  • keywords trunk-ported added; trunk-unported removed
  • status changed from closed to reopened
  • resolution fixed deleted
  • milestone changed from 1.1.6.6 to 1.3

Changed 3 years ago by BrianKoontz

  • status changed from reopened to assigned

Changed 3 years ago by BrianKoontz

  • status changed from assigned to testing

Changed 2 years ago by DotMG

  • status changed from testing to assigned

Changed 2 years ago by DotMG

  • owner changed from BrianKoontz to DotMG
  • status changed from assigned to accepted

Changed 2 years ago by DotMG

(In [1640]) refs #826

Added substr() to limit length of editnote

Changed 2 years ago by DotMG

  • status changed from accepted to testing

Changed 2 years ago by BrianKoontz

  • status changed from testing to commit

Tested OK.

Changed 2 years ago by BrianKoontz

  • status changed from commit to closed
  • resolution set to fixed

Changed 15 months ago by BrianKoontz

  • milestone changed from 1.3 to 1.3.1

Changed milestone to 1.3.1

Note: See TracTickets for help on using tickets.