Skip to content

Commit 67707d0

Browse files
committed
fix: remove string.js for sucurity issue
1. Upgrade Imgur to fix npm install 2. Upgrade less version for security 3. Change package name in package.json to fit npm package.json rule Signed-off-by: BoHong Li <a60814billy@gmail.com>
1 parent 22b29c4 commit 67707d0

7 files changed

Lines changed: 47 additions & 38 deletions

File tree

lib/models/note.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ var async = require('async')
1313
var moment = require('moment')
1414
var DiffMatchPatch = require('@hackmd/diff-match-patch')
1515
var dmp = new DiffMatchPatch()
16-
var S = require('string')
16+
17+
const {stripTags} = require('../../utils/string')
1718

1819
// core
1920
var config = require('../config')
@@ -338,7 +339,7 @@ module.exports = function (sequelize, DataTypes) {
338339
title = meta.title
339340
} else {
340341
var h1s = $('h1')
341-
if (h1s.length > 0 && h1s.first().text().split('\n').length === 1) { title = S(h1s.first().text()).stripTags().s }
342+
if (h1s.length > 0 && h1s.first().text().split('\n').length === 1) { title = stripTags(h1s.first().text()) }
342343
}
343344
if (!title) title = 'Untitled'
344345
return title
@@ -368,7 +369,7 @@ module.exports = function (sequelize, DataTypes) {
368369
if (/^tags/gmi.test($(value).text())) {
369370
var codes = $(value).find('code')
370371
for (let i = 0; i < codes.length; i++) {
371-
var text = S($(codes[i]).text().trim()).stripTags().s
372+
var text = stripTags($(codes[i]).text().trim())
372373
if (text) rawtags.push(text)
373374
}
374375
}

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "CodiMD",
2+
"name": "codimd",
33
"version": "1.3.1",
44
"description": "Realtime collaborative markdown notes on all platforms.",
55
"main": "app.js",
@@ -19,7 +19,7 @@
1919
"@hackmd/codemirror": "^5.41.2",
2020
"@hackmd/diff-match-patch": "^1.1.1",
2121
"@hackmd/idle-js": "^1.0.1",
22-
"@hackmd/imgur": "^0.4.0",
22+
"@hackmd/imgur": "^0.4.1",
2323
"@hackmd/js-sequence-diagrams": "^0.0.1-alpha.2",
2424
"@passport-next/passport-openid": "^1.0.0",
2525
"archiver": "^2.1.1",
@@ -117,7 +117,6 @@
117117
"spin.js": "^2.3.2",
118118
"sqlite3": "^4.0.1",
119119
"store": "^2.0.12",
120-
"string": "^3.3.3",
121120
"tedious": "^1.14.0",
122121
"toobusy-js": "^0.5.1",
123122
"turndown": "^5.0.1",
@@ -184,7 +183,7 @@
184183
"html-webpack-plugin": "4.0.0-beta.2",
185184
"imports-loader": "^0.8.0",
186185
"jsonlint": "^1.6.2",
187-
"less": "^2.7.1",
186+
"less": "^3.9.0",
188187
"less-loader": "^4.1.0",
189188
"mini-css-extract-plugin": "^0.4.1",
190189
"mocha": "^5.2.0",

public/js/cover.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030

3131
import { saveAs } from 'file-saver'
3232
import List from 'list.js'
33-
import S from 'string'
33+
import unescapeHTML from 'lodash/unescape'
3434

3535
const options = {
3636
valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags', 'pinned'],
@@ -397,7 +397,7 @@ function buildTagsFilter (tags) {
397397
for (let i = 0; i < tags.length; i++) {
398398
tags[i] = {
399399
id: i,
400-
text: S(tags[i]).unescapeHTML().s
400+
text: unescapeHTML(tags[i])
401401
}
402402
}
403403
filtertags = tags

public/js/extra.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ require('prismjs/components/prism-gherkin')
1313
import Prism from 'prismjs'
1414
import hljs from 'highlight.js'
1515
import PDFObject from 'pdfobject'
16-
import S from 'string'
1716
import { saveAs } from 'file-saver'
1817

18+
import escapeHTML from 'lodash/escape'
19+
import unescapeHTML from 'lodash/unescape'
20+
21+
import {stripTags} from '../../utils/string'
22+
1923
require('./lib/common/login')
2024
require('../vendor/md-toc')
2125
var Viz = require('viz.js')
@@ -157,7 +161,7 @@ export function renderTags (view) {
157161

158162
function slugifyWithUTF8 (text) {
159163
// remove html tags and trim spaces
160-
let newText = S(text).trim().stripTags().s
164+
let newText = stripTags(text.toString().trim())
161165
// replace all spaces in between to dashes
162166
newText = newText.replace(/\s+/g, '-')
163167
// slugify string to make it valid for attribute
@@ -492,22 +496,22 @@ export function finishView (view) {
492496
value: code
493497
}
494498
} else if (reallang === 'haskell' || reallang === 'go' || reallang === 'typescript' || reallang === 'jsx' || reallang === 'gherkin') {
495-
code = S(code).unescapeHTML().s
499+
code = unescapeHTML(code)
496500
result = {
497501
value: Prism.highlight(code, Prism.languages[reallang])
498502
}
499503
} else if (reallang === 'tiddlywiki' || reallang === 'mediawiki') {
500-
code = S(code).unescapeHTML().s
504+
code = unescapeHTML(code)
501505
result = {
502506
value: Prism.highlight(code, Prism.languages.wiki)
503507
}
504508
} else if (reallang === 'cmake') {
505-
code = S(code).unescapeHTML().s
509+
code = unescapeHTML(code)
506510
result = {
507511
value: Prism.highlight(code, Prism.languages.makefile)
508512
}
509513
} else {
510-
code = S(code).unescapeHTML().s
514+
code = unescapeHTML(code)
511515
const languages = hljs.listLanguages()
512516
if (!languages.includes(reallang)) {
513517
result = hljs.highlightAuto(code)
@@ -902,7 +906,7 @@ export function scrollToHash () {
902906

903907
function highlightRender (code, lang) {
904908
if (!lang || /no(-?)highlight|plain|text/.test(lang)) { return }
905-
code = S(code).escapeHTML().s
909+
code = escapeHTML(code)
906910
if (lang === 'sequence') {
907911
return `<div class="sequence-diagram raw">${code}</div>`
908912
} else if (lang === 'flow') {

public/js/history.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
/* global serverurl, moment */
33

44
import store from 'store'
5-
import S from 'string'
65
import LZString from 'lz-string'
76

7+
import escapeHTML from 'lodash/escape'
8+
89
import wurl from 'wurl'
910

1011
import {
@@ -276,8 +277,8 @@ function parseToHistory (list, notehistory, callback) {
276277
notehistory[i].fromNow = timestamp.fromNow()
277278
notehistory[i].time = timestamp.format('llll')
278279
// prevent XSS
279-
notehistory[i].text = S(notehistory[i].text).escapeHTML().s
280-
notehistory[i].tags = (notehistory[i].tags && notehistory[i].tags.length > 0) ? S(notehistory[i].tags).escapeHTML().s.split(',') : []
280+
notehistory[i].text = escapeHTML(notehistory[i].text)
281+
notehistory[i].tags = (notehistory[i].tags && notehistory[i].tags.length > 0) ? escapeHTML(notehistory[i].tags).split(',') : []
281282
// add to list
282283
if (notehistory[i].id && list.get('id', notehistory[i].id).length === 0) { list.add(notehistory[i]) }
283284
}

utils/string.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict'
2+
3+
function stripTags(s) {
4+
return s.replace(RegExp(`</?[^<>]*>`, 'gi'), '')
5+
}
6+
7+
exports.stripTags = stripTags

yarn.lock

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
resolved "https://registry.yarnpkg.com/@hackmd/idle-js/-/idle-js-1.0.1.tgz#89079a76d9c7bda87029660a708e72fbb2be3605"
3434
integrity sha512-yuv9BBdA5rk4TpmSrsdNgkLIyRt73hWyBEs7PhWhIozFcNv66JfUzXqA0eT3ToXX0163aVnbpHeJZRvcYy5Seg==
3535

36-
"@hackmd/imgur@^0.4.0":
37-
version "0.4.0"
38-
resolved "https://registry.yarnpkg.com/@hackmd/imgur/-/imgur-0.4.0.tgz#e5716f6a7a12e8011ceb57f46369fcc958623e19"
39-
integrity sha512-519G+fXIDu1LUwPU32nerot4wuP2pSDEBysOj9nX6IYL5qom/lo6vmp3bp0bg7SbtHWvmjZEDOermCrlqR18xw==
36+
"@hackmd/imgur@^0.4.1":
37+
version "0.4.1"
38+
resolved "https://registry.yarnpkg.com/@hackmd/imgur/-/imgur-0.4.1.tgz#9d51dafc4fd0baf36a8fb7a8a5c23f2f660d3ad2"
39+
integrity sha512-zvAt/4drM+nZG/yM12hJ7/DtkPffw/fzvr8oDp6twg5a04/HBoGha28vYrZP4fV/a5ZAAnRzxRRbeADxRfsGfA==
4040
dependencies:
4141
glob "^7.1.3"
4242
request "^2.88.0"
@@ -1976,7 +1976,7 @@ cliui@^4.0.0:
19761976
strip-ansi "^4.0.0"
19771977
wrap-ansi "^2.0.0"
19781978

1979-
clone@^2.1.1:
1979+
clone@^2.1.1, clone@^2.1.2:
19801980
version "2.1.2"
19811981
resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f"
19821982
integrity sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18=
@@ -5414,19 +5414,21 @@ less-loader@^4.1.0:
54145414
loader-utils "^1.1.0"
54155415
pify "^3.0.0"
54165416

5417-
less@^2.7.1:
5418-
version "2.7.3"
5419-
resolved "https://registry.yarnpkg.com/less/-/less-2.7.3.tgz#cc1260f51c900a9ec0d91fb6998139e02507b63b"
5420-
integrity sha512-KPdIJKWcEAb02TuJtaLrhue0krtRLoRoo7x6BNJIBelO00t/CCdJQUnHW5V34OnHMWzIktSalJxRO+FvytQlCQ==
5417+
less@^3.9.0:
5418+
version "3.9.0"
5419+
resolved "https://registry.yarnpkg.com/less/-/less-3.9.0.tgz#b7511c43f37cf57dc87dffd9883ec121289b1474"
5420+
integrity sha512-31CmtPEZraNUtuUREYjSqRkeETFdyEHSEPAGq4erDlUXtda7pzNmctdljdIagSb589d/qXGWiiP31R5JVf+v0w==
5421+
dependencies:
5422+
clone "^2.1.2"
54215423
optionalDependencies:
54225424
errno "^0.1.1"
54235425
graceful-fs "^4.1.2"
54245426
image-size "~0.5.0"
5425-
mime "^1.2.11"
5427+
mime "^1.4.1"
54265428
mkdirp "^0.5.0"
54275429
promise "^7.1.1"
5428-
request "2.81.0"
5429-
source-map "^0.5.3"
5430+
request "^2.83.0"
5431+
source-map "~0.6.0"
54305432

54315433
levn@^0.3.0, levn@~0.3.0:
54325434
version "0.3.0"
@@ -5982,7 +5984,7 @@ mime@1.4.1:
59825984
resolved "https://registry.yarnpkg.com/mime/-/mime-1.4.1.tgz#121f9ebc49e3766f311a76e1fa1c8003c4b03aa6"
59835985
integrity sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==
59845986

5985-
mime@^1.2.11:
5987+
mime@^1.4.1:
59865988
version "1.6.0"
59875989
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
59885990
integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==
@@ -8046,7 +8048,7 @@ request-promise-native@^1.0.5:
80468048
stealthy-require "^1.1.1"
80478049
tough-cookie "^2.3.3"
80488050

8049-
request@2.81.0, request@2.x, request@^2.61.0, request@^2.81.0, request@^2.86.0, request@^2.87.0, request@^2.88.0:
8051+
request@2.x, request@^2.61.0, request@^2.81.0, request@^2.83.0, request@^2.86.0, request@^2.87.0, request@^2.88.0:
80508052
version "2.88.0"
80518053
resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef"
80528054
integrity sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==
@@ -8829,11 +8831,6 @@ string-width@^3.0.0:
88298831
is-fullwidth-code-point "^2.0.0"
88308832
strip-ansi "^5.1.0"
88318833

8832-
string@^3.3.3:
8833-
version "3.3.3"
8834-
resolved "https://registry.yarnpkg.com/string/-/string-3.3.3.tgz#5ea211cd92d228e184294990a6cc97b366a77cb0"
8835-
integrity sha1-XqIRzZLSKOGEKUmQpsyXs2anfLA=
8836-
88378834
string_decoder@^1.0.0, string_decoder@^1.1.1:
88388835
version "1.2.0"
88398836
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.2.0.tgz#fe86e738b19544afe70469243b2a1ee9240eae8d"

0 commit comments

Comments
 (0)