3
Hello,
I’m learning development and I don’t know much about security.
I’m making a web application using Nodejs
+ Expressjs
+ AngularJs
+ MongoDB
. I did it this way, Mongodb data is sent to a URL using the method Post
, and then I "access" this data with Angularjs and show it on the screen. I would like to know how unsafe this is.
Follows code:
First I created a Schema from my Mongodb collection:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var userSchema = new Schema({
nome: String,
idade: Number,
CPF: String,
email: String
});
var User = mongoose.model('User' , userSchema );
module.exports = User;
Then I took this Schema in a file and created a URL and sent the data using method POST
var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var User = require('../models/users');
//Se aqui for router.get os dados serão exibidos na URL localhost/api/users
//Então usei router.post
router.post('/api/users' , function(req, res, next){
User.find(function(err, users){
res.json(users);
});
});
module.exports = router;
Finally, I took the URL data and displayed it on the screen with Angular:
app.controller("RBScontroller", function ($scope, $http) {
$scope.enviar = function enviar(){
var ApiMongo = 'http://localhost:3000/api/users';
$scope.users = [];
$scope.loading = true;
$http.post(ApiMongo).success(function(data) {
console.log(data);
$scope.users = data;
$scope.loading = false;
}).error(function(msg) {
angular.element($(function(){alert("Fail")}));
$scope.loading = false;
});
}
});
Does this method leave the data exposed in any way? Thank you