summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRatan Gupta <ratagupt@linux.vnet.ibm.com>2019-07-11 22:02:25 +0300
committerEd Tanous <ed.tanous@intel.com>2019-08-02 23:25:05 +0300
commit845cb7d54fb72d2bbb0fdb147a71f03009596727 (patch)
tree41dd0064dbdf4cf8b695dbdf49121cd1f8e7ee09 /include
parent94e1b82826762404589e61904139bba3a86964bd (diff)
downloadbmcweb-845cb7d54fb72d2bbb0fdb147a71f03009596727.tar.xz
Change the permission of the session database
bmcweb_persistent_data.json have all the session info, any user having less privilege can get access to this file which is having sensitive data(user authentication token) This commit fixes this bug by allowing the read write permission to the owner and group and others would not be having either read or write permission. TestedBy: -> Create the redfish session -> check the permission of the file. -> Stop the bmcweb and remove the session file restart the bmcweb and check the permission of the file. -> Create the session again and perfrom the GET request on Manager,AccountService to verify the other operation is working. Signed-off-by: Ratan Gupta <ratagupt@linux.vnet.ibm.com> Change-Id: I1e69ac147a2cfc3dff150322aee1f430ac552a5a
Diffstat (limited to 'include')
-rw-r--r--include/persistent_data_middleware.hpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/include/persistent_data_middleware.hpp b/include/persistent_data_middleware.hpp
index b384f02304..1162fc5b97 100644
--- a/include/persistent_data_middleware.hpp
+++ b/include/persistent_data_middleware.hpp
@@ -8,6 +8,7 @@
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
+#include <filesystem>
#include <nlohmann/json.hpp>
#include <pam_authenticate.hpp>
#include <random>
@@ -20,13 +21,16 @@ namespace crow
namespace persistent_data
{
+namespace fs = std::filesystem;
+
class Middleware
{
- // todo(ed) should read this from a fixed location somewhere, not CWD
- static constexpr const char* filename = "bmcweb_persistent_data.json";
int jsonRevision = 1;
public:
+ // todo(ed) should read this from a fixed location somewhere, not CWD
+ static constexpr const char* filename = "bmcweb_persistent_data.json";
+
struct Context
{
};
@@ -151,6 +155,12 @@ class Middleware
void writeData()
{
std::ofstream persistentFile(filename);
+
+ // set the permission of the file to 640
+ fs::perms permission = fs::perms::owner_read | fs::perms::owner_write |
+ fs::perms::group_read;
+ fs::permissions(filename, permission);
+
nlohmann::json data{
{"sessions", SessionStore::getInstance().authTokens},
{"system_uuid", systemUuid},