Git Product home page Git Product logo

Comments (2)

jksdua avatar jksdua commented on July 17, 2024

Source code disclosure using public directory middleware. Possible in express, restify, connect, koa etc if configured incorrectly.

Directory structure

- /fonts
- /images
- /scripts
- /stylesheets
- /index.html
- /app.js

app.js

var express = require('express');
var app = express();

// expose fonts, stylesheets etc to the front end
app.use(express.static(__dirname));

app.listen(1234);

Now the client side app can be loaded at http://localhost:3000. Fonts and scripts can be referenced in index.html using http://localhost:3000/fonts or http://localhost:3000/scripts. However, it also exposes sensitive files such as package.json or app.js (this file) or any other file in the app directory. Imagine things such as config files, model or controller code etc. Yikes!

from nodegoat.

jksdua avatar jksdua commented on July 17, 2024

Not sure what the theme of the application is but sensitive data exposure using cookies might be useful.

Simple - unencrypted cookies

var express = require('express');
var app = express();

app.use(express.cookieParser());

app.use(function(req, res) {
    res.cookie('secret', 'data');
});

app.listen(1234);

Complex - Weak or default encryption passphrase

var express = require('express');
var app = express();

app.use(express.cookieParser('secret'));

app.use(function(req, res) {

    // we've added a passphrase key but our cookie can still be cracked if the cookie data is relatively small
    res.cookie('total_price', '100', { signed: true });
});

app.listen(1234);

We can crack the cookie since we know the HMAC algorithm (algorithm and key are prepended to the cookie value). Method: base64 decode, then use node crypto functions to crack the cookie and/or generate our own :). The key thing with this would be to ensure we use a simple cookie value such as a common password or a small integer.

It would be nice to include another gotcha somewhere around explicitly setting signed: true when creating the cookie if the cookie is secret. Otherwise, the cookie is not encrypted. Not a very safe default!

P.S I am just throwing ideas out there since I don't have access to Google Groups forum and dont know the process for getting stuff into the app. Happy to send pull requests as well.

from nodegoat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.