mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-11-29 03:42:42 +01:00
Sanitize author descriptions before they are stored or returned
This commit is contained in:
1 parent
83dce682e8
commit
bf1c5688b9
3 files changed
+169
-4
No files matched your search
@@ -11,11 +11,24 @@ const CoverManager = require('../managers/CoverManager')
|
||||
const AuthorFinder = require('../finders/AuthorFinder')
|
||||
|
||||
const { reqSupportsWebp, isValidASIN, clampPositiveInt } = require('../utils/index')
|
||||
const htmlSanitizer = require('../utils/htmlSanitizer')
|
||||
|
||||
const naturalSort = createNewSortInstance({
|
||||
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
|
||||
})
|
||||
|
||||
/**
|
||||
* @param {string} description
|
||||
* @returns {string|null}
|
||||
*/
|
||||
function sanitizeAuthorDescription(description) {
|
||||
const sanitizedDescription = htmlSanitizer.sanitize(description)
|
||||
if (sanitizedDescription !== description) {
|
||||
Logger.debug(`[AuthorController] Sanitized description from "${description}" to "${sanitizedDescription}"`)
|
||||
}
|
||||
return sanitizedDescription || null
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef RequestUserObject
|
||||
* @property {import('../models/User')} user
|
||||
@@ -101,6 +114,10 @@ class AuthorController {
|
||||
payload[key] = req.body[key]
|
||||
}
|
||||
}
|
||||
if (payload.description) {
|
||||
payload.description = sanitizeAuthorDescription(payload.description)
|
||||
}
|
||||
|
||||
if (!Object.keys(payload).length) {
|
||||
Logger.error(`[AuthorController] Invalid request payload. No valid keys found`, req.body)
|
||||
return res.status(400).send('Invalid request payload. No valid keys found')
|
||||
@@ -364,9 +381,12 @@ class AuthorController {
|
||||
}
|
||||
}
|
||||
|
||||
if (authorData.description && req.author.description !== authorData.description) {
|
||||
req.author.description = authorData.description
|
||||
hasUpdates = true
|
||||
if (authorData.description) {
|
||||
const description = sanitizeAuthorDescription(authorData.description)
|
||||
if (req.author.description !== description) {
|
||||
req.author.description = description
|
||||
hasUpdates = true
|
||||
}
|
||||
}
|
||||
|
||||
if (hasUpdates) {
|
||||
|
||||
Reference in new issue
Block a user