Question: βWhy are AJAX request data not encrypted from Braintree JS β and the response is not related to HTTPS.
Yes, HTTPS is required to encrypt traffic in the production process - in which case it will encrypt already encrypted card data, but HTTPS is neither a question nor an answer here.
If you look at the Braintree documentation ( Example here ), you will notice that each input in the example form has added the data-encrypted-name attribute:
<input type="text" size="20" autocomplete="off" data-encrypted-name="number" />
The documentation then indicates this code:
braintree.onSubmitEncryptForm('braintree-payment-form');
When the form is submitted, the code in braintree.js , checks the form, looks at the plain text in each marked input , encrypts it, saves the encrypted values ββin accordance with the data--encrypted-name attributes, and then that the encrypted data is used when the form is transmitted through HTTP / HTTPS.
In the above code example, AngularJS OP contains data-encrypted-name attributes on some input (I donβt know if they need to be on all of them), but just marking the input is not enough, Encryption function of raw input values ββ(or, in this case , model data) should still be called, and then this encrypted model can be sent to POST back to the server.
The problem, on the other hand:
- Form creates a model
- Model sent over HTTP to the server
Fixed implementation:
- Form creates a model
- Braintree.js is called to encrypt some parts of the model.
- The encrypted model is sent via HTTP (or HTTPS during production) to the server
Here plunkr someone else showed one way to encrypt AngularJS model data on the fly:
http://plnkr.co/edit/2kF9Im?p=preview
If it were me, I would just call braintree.encrypt() in each field immediately before submitting the form, and not every keystroke - or change the directive to work on the form during submission.