jonhobbs
jonhobbs

Reputation: 27962

Form post parameters ending up in URL

This is going to be a difficult one to explain but basically I have an angular application with a login form which runs a function on submit which sends an ajax request to the server to do the login.

Now, I'm not using ng-submit but hijacking the normal submit attribute like this:

<form my-form submit="controllername.doSubmit()">

I then have an angular directive called "my-form" which uses {require: 'form'} in it's definition object and then does this in the postLink function:

element.bind('submit', function(event)
{
    // Removed for brevity

    scope.$apply(scope.submit);
});

So, basically this form submit stuff was written a long time ago and does a lot of other stuff like triggering form validation and stuff by default so I don't wnt to rewrite any of this or go back to using ng-submit. Aside form anything else I have a few big apps using this code which would need to change a lot.

Anyway, it all works fine on the surface but if I fill in the log in form and then do some other stuff (including filling in other forms set up the same way) and then leave my laptop for a few days and come back to the page, somehow all the form data has been added into the URL bar, after the ?? and before the # including the password in plain view!

Not sure why this doesn't happen straight away, ony after un-sleeping the PC, and not always. The other weird thing is that the names of the parameters are not the original ones (email, password) but the names of the parameters of the first form currently on the page (actionStatus, required), so Chrome is obviously getting very confused.

My instinct tells me that when the form is submitted, the formData is being stored somewhere for later because I'm not cancelling the default action of the form correctly when I'm running my javascript function and because it's a single page application that formData never leaves the memory. It's then thinking it's gone to a new page and putting that data in the URl, but it's getting the names wrong because the forms on the page has changed.

Sorry, I can't provide more code, just a fairly wooly description but I don't know what else to say really, it's all very strange.

Upvotes: 0

Views: 157

Answers (1)

jonhobbs
jonhobbs

Reputation: 27962

I finally have an answer to this and the answer is totally unexpected.

I use a plugin called browserSync to sync multiple browsers I'm testing on and it had a feature called form syncing switched on.

I had chrome open and when I opened up another browser (typically in the morning when the computer first woke up) I had to log in and because they were on different pages it was copying my login details from Firefox into the first form it found in my existing chrome window. It was also putting the contents of Firefox's login form into chrome's URL.

Crazy.

Upvotes: 2

Related Questions