Git Product home page Git Product logo

Comments (7)

ljharb avatar ljharb commented on August 20, 2024

This is kind of a huge problem, what with security and privacy. Does anyone know how it can be fixed?

from forms.

powmedia avatar powmedia commented on August 20, 2024

I haven't used it in a while but I think this fork fixes the problem: https://github.com/tdryer/forms

On 2 Apr 2012, at 06:59, Jordan Harband wrote:

This is kind of a huge problem, what with security and privacy. Does anyone know how it can be fixed?


Reply to this email directly or view it on GitHub:
#13 (comment)

from forms.

johngeorgewright avatar johngeorgewright commented on August 20, 2024

This is a scary problem... however, looking at your code I think can see why it's happening. You're using the same object between different routes. Your signupForm will only ever be constructed once. Although I haven't tested this, I believe re-factoring your code like so should fix your problem:

//controller.js, imported into app.js

var forms = require('../lib/forms'),
    fields = forms.fields,
    validators = forms.validators;

var signupForm = function() {
    return forms.create({

        first_name: fields.string({ required: true }),
        last_name: fields.string({ required: true }),
        email: fields.email({ required: true }),
        password: fields.password({ required: true }),
        password_confirm: fields.password({
            required: true,
            validators: validators.matchField('password')
        })

    });
};

module.exports = function(app) {

    app.get('/signup', function(req, res, next) {
        res.render('signup', {
            signupForm: signupForm().toHTML()
        });
    });

    app.post('/signup', function(req, res, next) {
        signupForm().handle(req.body, {
            success: function(form) {
                res.redirect('/app');
            },
            other: function(form) {
                res.render('signup', {
                    form: form.toHTML()
                });
            }
        });
    });
};

from forms.

ljharb avatar ljharb commented on August 20, 2024

The form should only need to be created once. However, its value should not persist beyond a single request, and refactoring our code to remove the benefit of caching seems inappropriate. It seems that tdryer@86f354d fixes the problem, so it just needs to be merged into the main project.

from forms.

johngeorgewright avatar johngeorgewright commented on August 20, 2024

Ahha... agreed. Much better way of go about it.

from forms.

ljharb avatar ljharb commented on August 20, 2024

Please see the comments on #16 for an update on this issue

from forms.

ljharb avatar ljharb commented on August 20, 2024

Fixed by #16

from forms.

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.