mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-24 02:36:31 -05:00
Ensure case-sensitive DB queries on MySQL/MariaDB
MySQLs string comparisons are case-insensitive by default. This allows to hide notes by creating a new note with an alias that equals the lower-cased alias of another note. The new note is returned first by MySQL, so the original one is not accessible anymore. This fixes the problem by using an explicit binary comparison in the affected queries. See https://dev.mysql.com/doc/refman/8.0/en/case-sensitivity.html Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
c543dc1f23
commit
380587b7fd
2 changed files with 15 additions and 6 deletions
|
@ -18,6 +18,7 @@ const S = require('string')
|
|||
// core
|
||||
const config = require('../config')
|
||||
const logger = require('../logger')
|
||||
const utils = require('../utils')
|
||||
|
||||
// ot
|
||||
const ot = require('../ot')
|
||||
|
@ -191,7 +192,9 @@ module.exports = function (sequelize, DataTypes) {
|
|||
parseNoteIdByAlias: function (_callback) {
|
||||
// try to parse note id by alias (e.g. doc)
|
||||
Note.findOne({
|
||||
where: {
|
||||
where: utils.isMySQL(sequelize)
|
||||
? sequelize.where(sequelize.fn('BINARY', sequelize.col('alias')), noteId)
|
||||
: {
|
||||
alias: noteId
|
||||
}
|
||||
}).then(function (note) {
|
||||
|
@ -296,7 +299,9 @@ module.exports = function (sequelize, DataTypes) {
|
|||
try {
|
||||
if (shortId.isValid(noteId)) {
|
||||
Note.findOne({
|
||||
where: {
|
||||
where: utils.isMySQL(sequelize)
|
||||
? sequelize.where(sequelize.fn('BINARY', sequelize.col('shortid')), noteId)
|
||||
: {
|
||||
shortid: noteId
|
||||
}
|
||||
}).then(function (note) {
|
||||
|
|
|
@ -4,6 +4,10 @@ exports.isSQLite = function isSQLite (sequelize) {
|
|||
return sequelize.options.dialect === 'sqlite'
|
||||
}
|
||||
|
||||
exports.isMySQL = function isMySQL (sequelize) {
|
||||
return ['mysql', 'mariadb'].includes(sequelize.options.dialect)
|
||||
}
|
||||
|
||||
exports.getImageMimeType = function getImageMimeType (imagePath) {
|
||||
const fileExtension = /[^.]+$/.exec(imagePath)
|
||||
|
||||
|
|
Loading…
Reference in a new issue