fix: use nanoid instead of shortid
shortid is deprecated and they recommend nanoid instead. We're not sure if this has to do with possible name collisions or enumerability, but to be sure and on the safe side, we're changing this. nanoid seems quite safe since it uses node's crypto module underneath. Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
committed by
Philip Molares
parent
c449d3a815
commit
637c451486
@@ -7,7 +7,7 @@ const base64url = require('base64url')
|
||||
const md = require('markdown-it')()
|
||||
const metaMarked = require('@hedgedoc/meta-marked')
|
||||
const cheerio = require('cheerio')
|
||||
const shortId = require('shortid')
|
||||
const nanoid = require('nanoid')
|
||||
const Sequelize = require('sequelize')
|
||||
const async = require('async')
|
||||
const moment = require('moment')
|
||||
@@ -37,7 +37,7 @@ module.exports = function (sequelize, DataTypes) {
|
||||
type: DataTypes.STRING,
|
||||
unique: true,
|
||||
allowNull: false,
|
||||
defaultValue: shortId.generate
|
||||
defaultValue: () => nanoid.nanoid(10)
|
||||
},
|
||||
alias: {
|
||||
type: DataTypes.STRING,
|
||||
@@ -297,8 +297,12 @@ module.exports = function (sequelize, DataTypes) {
|
||||
parseNoteIdByShortId: function (_callback) {
|
||||
// try to parse note id by shortId
|
||||
try {
|
||||
if (shortId.isValid(noteId)) {
|
||||
// old short ids generated by the `shortid` package could be from 7 to 14 characters long
|
||||
// new ones generated by the `nanoid` package are always 10 characters long
|
||||
if (noteId && noteId.length >= 7 && noteId.length <= 14) {
|
||||
Note.findOne({
|
||||
// MariaDB and MySQL do case-insensitive comparison by default (unless a collation charset like utf8mb4 is used)
|
||||
// The binary conversion ensures, case-sensitive comparison.
|
||||
where: utils.isMySQL(sequelize)
|
||||
? sequelize.where(sequelize.fn('BINARY', sequelize.col('shortid')), noteId)
|
||||
: {
|
||||
|
||||
@@ -4,7 +4,7 @@ const Sequelize = require('sequelize')
|
||||
const async = require('async')
|
||||
const moment = require('moment')
|
||||
const childProcess = require('child_process')
|
||||
const shortId = require('shortid')
|
||||
const nanoid = require('nanoid')
|
||||
const path = require('path')
|
||||
|
||||
const Op = Sequelize.Op
|
||||
@@ -44,7 +44,7 @@ function createDmpWorker () {
|
||||
|
||||
function sendDmpWorker (data, callback) {
|
||||
if (!dmpWorker) dmpWorker = createDmpWorker()
|
||||
const cacheKey = Date.now() + '_' + shortId.generate()
|
||||
const cacheKey = Date.now() + '_' + nanoid.nanoid()
|
||||
dmpCallbackCache[cacheKey] = callback
|
||||
data = Object.assign(data, {
|
||||
cacheKey
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
'use strict'
|
||||
// external modules
|
||||
const shortId = require('shortid')
|
||||
const nanoid = require('nanoid')
|
||||
|
||||
module.exports = function (sequelize, DataTypes) {
|
||||
const Temp = sequelize.define('Temp', {
|
||||
id: {
|
||||
type: DataTypes.STRING,
|
||||
primaryKey: true,
|
||||
defaultValue: shortId.generate
|
||||
defaultValue: nanoid.nanoid
|
||||
},
|
||||
data: {
|
||||
type: DataTypes.TEXT
|
||||
|
||||
@@ -2,7 +2,7 @@ const models = require('../../models')
|
||||
const logger = require('../../logger')
|
||||
const config = require('../../config')
|
||||
const errors = require('../../errors')
|
||||
const shortId = require('shortid')
|
||||
const nanoid = require('nanoid')
|
||||
const moment = require('moment')
|
||||
const querystring = require('querystring')
|
||||
|
||||
@@ -36,7 +36,7 @@ exports.createGist = function createGist (req, res, note) {
|
||||
client_id: config.github.clientID,
|
||||
redirect_uri: config.serverURL + '/auth/github/callback/' + models.Note.encodeNoteId(note.id) + '/gist',
|
||||
scope: 'gist',
|
||||
state: shortId.generate()
|
||||
state: nanoid.nanoid()
|
||||
}
|
||||
const query = querystring.stringify(data)
|
||||
res.redirect('https://github.com/login/oauth/authorize?' + query)
|
||||
|
||||
Reference in New Issue
Block a user