mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 00:46:16 -04:00
Security: Fix revision parsing (#5772)
A carefully crated URL can cause Etherpad to hang.
This commit is contained in:
parent
1d289520eb
commit
1e98033632
9 changed files with 325 additions and 29 deletions
|
@ -33,6 +33,7 @@ const exportTxt = require('../utils/ExportTxt');
|
|||
const importHtml = require('../utils/ImportHtml');
|
||||
const cleanText = require('./Pad').cleanText;
|
||||
const PadDiff = require('../utils/padDiff');
|
||||
const { checkValidRev, isInt } = require('../utils/checkValidRev');
|
||||
|
||||
/* ********************
|
||||
* GROUP FUNCTIONS ****
|
||||
|
@ -777,6 +778,13 @@ exports.createDiffHTML = async (padID, startRev, endRev) => {
|
|||
|
||||
// get the pad
|
||||
const pad = await getPadSafe(padID, true);
|
||||
const headRev = pad.getHeadRevisionNumber();
|
||||
if (startRev > headRev)
|
||||
startRev = headRev;
|
||||
|
||||
if (endRev > headRev)
|
||||
endRev = headRev;
|
||||
|
||||
let padDiff;
|
||||
try {
|
||||
padDiff = new PadDiff(pad, startRev, endRev);
|
||||
|
@ -822,9 +830,6 @@ exports.getStats = async () => {
|
|||
** INTERNAL HELPER FUNCTIONS *
|
||||
**************************** */
|
||||
|
||||
// checks if a number is an int
|
||||
const isInt = (value) => (parseFloat(value) === parseInt(value, 10)) && !isNaN(value);
|
||||
|
||||
// gets a pad safe
|
||||
const getPadSafe = async (padID, shouldExist, text, authorId = '') => {
|
||||
// check if padID is a string
|
||||
|
@ -854,31 +859,6 @@ const getPadSafe = async (padID, shouldExist, text, authorId = '') => {
|
|||
return padManager.getPad(padID, text, authorId);
|
||||
};
|
||||
|
||||
// checks if a rev is a legal number
|
||||
// pre-condition is that `rev` is not undefined
|
||||
const checkValidRev = (rev) => {
|
||||
if (typeof rev !== 'number') {
|
||||
rev = parseInt(rev, 10);
|
||||
}
|
||||
|
||||
// check if rev is a number
|
||||
if (isNaN(rev)) {
|
||||
throw new CustomError('rev is not a number', 'apierror');
|
||||
}
|
||||
|
||||
// ensure this is not a negative number
|
||||
if (rev < 0) {
|
||||
throw new CustomError('rev is not a negative number', 'apierror');
|
||||
}
|
||||
|
||||
// ensure this is not a float value
|
||||
if (!isInt(rev)) {
|
||||
throw new CustomError('rev is a float value', 'apierror');
|
||||
}
|
||||
|
||||
return rev;
|
||||
};
|
||||
|
||||
// checks if a padID is part of a group
|
||||
const checkGroupPad = (padID, field) => {
|
||||
// ensure this is a group pad
|
||||
|
|
|
@ -172,6 +172,9 @@ class Pad {
|
|||
|
||||
async getInternalRevisionAText(targetRev) {
|
||||
const keyRev = this.getKeyRevisionNumber(targetRev);
|
||||
const headRev = this.getHeadRevisionNumber();
|
||||
if (targetRev > headRev)
|
||||
targetRev = headRev;
|
||||
const [keyAText, changesets] = await Promise.all([
|
||||
this._getKeyRevisionAText(keyRev),
|
||||
Promise.all(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue