From c95d469eb32ce67247d02be7c94eb947d136c063 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 7 Oct 2013 14:31:57 +0100 Subject: [PATCH 1/8] Updated to latest version of express closes #875 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 103a53dc60..496c1ebae8 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "engineStrict": true, "dependencies": { - "express": "3.3.4", + "express": "3.4.0", "express-hbs": "0.2.2", "connect-slashes": "0.0.9", "node-polyglot": "0.2.1", From d169bba3f81e0f1ef962acbb3a133beecc3ebab2 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 7 Oct 2013 16:42:25 +0100 Subject: [PATCH 2/8] Updated to latest version of express-hbs issue #830 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 496c1ebae8..af42ec5dd4 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "engineStrict": true, "dependencies": { "express": "3.4.0", - "express-hbs": "0.2.2", + "express-hbs": "0.3.0", "connect-slashes": "0.0.9", "node-polyglot": "0.2.1", "moment": "2.1.0", From c9235ccb0b2f3051714e178b787d19910cf2f35a Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Mon, 7 Oct 2013 13:02:57 -0400 Subject: [PATCH 3/8] Escaping several fields to prevent XSS issue #938 - escapes post's title field - escapes settings title, description, email - escapes user's name field - includes test for post title --- core/server/models/post.js | 2 +- core/server/models/settings.js | 12 ++++++++++++ core/server/models/user.js | 7 +++++++ core/test/unit/api_posts_spec.js | 12 ++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/core/server/models/post.js b/core/server/models/post.js index 74a197c263..a25e1a4b97 100644 --- a/core/server/models/post.js +++ b/core/server/models/post.js @@ -51,7 +51,7 @@ Post = GhostBookshelf.Model.extend({ this.set('html', converter.makeHtml(this.get('markdown'))); - this.set('title', this.get('title').trim()); + this.set('title', this.escape('title').trim()); if (this.hasChanged('status') && this.get('status') === 'published') { if (!this.get('published_at')) { diff --git a/core/server/models/settings.js b/core/server/models/settings.js index 5faf9e301a..ba8d299aca 100644 --- a/core/server/models/settings.js +++ b/core/server/models/settings.js @@ -73,7 +73,19 @@ Settings = GhostBookshelf.Model.extend({ validation[validationName].apply(validation, validationOptions); }, this); } + }, + + + saving: function () { + + // All blog setting keys that need their values to be escaped. + if (this.get('type') === 'blog' && _.contains(['title', 'description', 'email'], this.get('key'))) { + this.set('value', this.escape('value')); + } + + return GhostBookshelf.Model.prototype.saving.apply(this, arguments); } + }, { read: function (_key) { // Allow for just passing the key instead of attributes diff --git a/core/server/models/user.js b/core/server/models/user.js index 894a3df261..2e41e10203 100644 --- a/core/server/models/user.js +++ b/core/server/models/user.js @@ -55,6 +55,13 @@ User = GhostBookshelf.Model.extend({ } }, + saving: function () { + + this.set('name', this.escape('name')); + + return GhostBookshelf.Model.prototype.saving.apply(this, arguments); + }, + posts: function () { return this.hasMany(Posts, 'created_by'); }, diff --git a/core/test/unit/api_posts_spec.js b/core/test/unit/api_posts_spec.js index 6731d9222b..48e3b56301 100644 --- a/core/test/unit/api_posts_spec.js +++ b/core/test/unit/api_posts_spec.js @@ -367,4 +367,16 @@ describe('Post Model', function () { done(); }).then(null, done); }); + + it('should escape the title', function (done) { + + new PostModel().fetch().then(function(model) { + return model.set({'title': ''}).save(); + }).then(function(saved) { + saved.get('title').should.eql('<script>alert("hello world")</script>'); + done(); + }).otherwise(done); + + }); + }); From 95f9fce3be96ce3508b51c109111d2ebd67637b6 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Wed, 9 Oct 2013 19:11:29 +0100 Subject: [PATCH 4/8] Swapping escape to sanitze issue #938 - rather than using escape, use node-validatiors santize function which is designed for preventing xss vectors - added listener for changes to both editor and settings page - added more sanitization to the user model - consistently use triple-braces when outputting blog post titles --- core/client/tpl/list-item.hbs | 2 +- core/client/views/editor.js | 6 ++++++ core/client/views/settings.js | 21 +++++++++++++++------ core/server/helpers/tpl/nav.hbs | 2 +- core/server/models/base.js | 7 ++++++- core/server/models/post.js | 2 +- core/server/models/settings.js | 2 +- core/server/models/user.js | 6 +++++- core/test/unit/api_posts_spec.js | 10 +++++----- 9 files changed, 41 insertions(+), 17 deletions(-) diff --git a/core/client/tpl/list-item.hbs b/core/client/tpl/list-item.hbs index ae4b22dbb5..78506151f4 100644 --- a/core/client/tpl/list-item.hbs +++ b/core/client/tpl/list-item.hbs @@ -1,5 +1,5 @@ -

{{title}}

+

{{{title}}}