Removing the x-powered-by header

699 views
Skip to first unread message

Gary Cox

unread,
Mar 25, 2014, 9:08:13 AM3/25/14
to sai...@googlegroups.com
Having the x-powered-by header is a security issue.  I'm trying to remove it but have not been successful in doing so.  I added the following code in my config/local.js and reloaded the app.  The header was still present, how do you remove headers on the response?

express: {
    customMiddleware: function (app) {
        app.disable('x-powered-by');
        app.use(function headers(req, res, next) {
            res.removeHeader("X-Powered-By");
            next();
        });
    }
  }

Chad McElligott

unread,
Mar 25, 2014, 11:28:13 AM3/25/14
to sai...@googlegroups.com
The X-Powered-By header is added after all middleware have been processed on the request. If you want to change it, you'll need to alter sails core. The way express handles this is by conditionalizing it underneath an app setting: app.disable('x-powered-by')

Edy

unread,
Mar 25, 2014, 11:29:44 AM3/25/14
to sai...@googlegroups.com
instead of removing the header, you can modify it:

module.exports.express = {
middleware: {
poweredBy: function xPoweredBy (req, res, next) {
res.header('X-Powered-By', 'my fancy app');
next();
}
}
};

Ambroise Dhenain

unread,
Mar 25, 2014, 11:30:27 AM3/25/14
to Edy, sai...@googlegroups.com
Why is that a security issue?
--
Cordialement,

M. Ambroise Dhenain.

Joe Polastre

unread,
Mar 25, 2014, 11:44:28 AM3/25/14
to Edy, sai...@googlegroups.com
If you use nginx, you can also just remove it altogether (this is what
we are doing, since it is a security risk):

http://wiki.nginx.org/HttpProxyModule#proxy_hide_header

Gary Cox

unread,
Mar 25, 2014, 11:50:19 AM3/25/14
to sai...@googlegroups.com, Edy
@Ambroise - The security issue is having this header tell an attacker what you are using as your backend.  They can then pull the source down and find vulnerabilities easier.  We had our system pen tested and the testers told us we need to remove that header.

Joe Polastre

unread,
Mar 25, 2014, 11:52:36 AM3/25/14
to Gary Cox, sai...@googlegroups.com, Edy
It opens your system up to *automated* attacks. By telling an
automated script the software and version that you're running, the
attacker can automatically attack any known vulnerabilities in that
version of software. It is a low risk security vulnerability, but a
vulnerability none-the-less. Plus, it serves no meaningful purpose to
the customer/user/application, so why even bother transmitting it?

Ambroise Dhenain

unread,
Mar 25, 2014, 11:52:28 AM3/25/14
to Gary Cox, sai...@googlegroups.com, Edy
Okay, thanks. It's not a security issue by itself but lead to a security breach.

Rob Wormald

unread,
Mar 25, 2014, 1:09:14 PM3/25/14
to Ambroise Dhenain, Gary Cox, sai...@googlegroups.com, Edy
Why not change it to ASP.net? Should confuse the hell out of any automated attacks…

Joe Polastre

unread,
Mar 25, 2014, 1:31:43 PM3/25/14
to Rob Wormald, Ambroise Dhenain, Gary Cox, sai...@googlegroups.com, Edy
Or just invite more of them ;)

On Tue, Mar 25, 2014 at 1:09 PM, Rob Wormald <rob.w...@innitapps.com> wrote:
> Why not change it to ASP.net? Should confuse the hell out of any automated
> attacks...

Edy

unread,
Mar 26, 2014, 5:03:27 AM3/26/14
to sai...@googlegroups.com
i found out how you can remove the the x-powered-by header. you have to disable both the sails poweredBy middleware and the express header:

module.exports.express = {
middleware: {
poweredBy: false
},

customMiddleware: function (app) {
app.disable('x-powered-by');
}
};

Am Dienstag, 25. März 2014 14:08:13 UTC+1 schrieb Gary Cox:

Ambroise Dhenain

unread,
Mar 26, 2014, 5:06:48 AM3/26/14
to Edy, sai...@googlegroups.com
Don't you think that would be a good idea to do it by default? I mean in sails itself. Because from what I understand it just completely useless and nobody should use it.
Reply all
Reply to author
Forward
0 new messages