Rule Definition
Avoid having MongoDB databases access without authentication activated.Accessing a database without a proper authentication will harm security of data. One should set user authentication over a database.
Remediation
Set authentication for database before accessing.
Violation Code Sample
MongoClientURI connstr = new MongoClientURI("mongodb://admin:password@localhost:27017");
DB database = connstr.getDB("IndexingCheck");
or using springData
ApplicationContext ctx = new ClassPathXmlApplicationContext("web_configg.xml");
SpringMongoConfig1 mongoOperation1 = (SpringMongoConfig1) ctx.getBean("mongoURI");
MongoClient mongoClient = new MongoClient(mongoOperation1.uri);
Fixed Code Sample
MongoClientURI connstr = new MongoClientURI("mongodb://admin:@localhost:27017");
DB database = connstr.getDB("IndexingCheck");
MongoClientURI connstr = new MongoClientURI("mongodb://:password@localhost:27017");
DB database = connstr.getDB("IndexingCheck");
MongoClient mongo = new MongoClient("localhost", 27017);
Related Technologies
Technical Criterion
Programming Practices - Structuredness
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.