Skip to content

Commit 6dc2441

Browse files
committed
https://github.com/haxtheweb/issues/security/advisories/GHSA-5fpv-5qvh-7cf3
1 parent 2a0ad43 commit 6dc2441

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

src/lib/HAXCMS.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,39 @@ class HAXCMSClass {
17851785
this.refreshPrivateKey = uuidv4();
17861786
fs.writeFileSync(path.join(this.configDirectory, ".rpk"), this.refreshPrivateKey);
17871787
}
1788+
// allow for loading in user defined config
1789+
// pk/rpk test for files that can contain these
1790+
try {
1791+
this.user = JSON.parse(fs.readFileSync(path.join(this.configDirectory, ".user")),
1792+
{encoding:'utf8', flag:'r'}, 'utf8');
1793+
this.superUser = {...this.user};
1794+
}
1795+
catch (e) {
1796+
console.warn('***************************************************************');
1797+
console.warn('\nHAXcms USER CONFIGURATION FILE NOT FOUND, creating default user');
1798+
console.warn(`${path.join(this.configDirectory, ".user")} is being created with default credentials`);
1799+
console.warn("MAKE SURE YOU EDIT THIS FILE IF PUTTING IN PRODUCTION!!!!!");
1800+
console.warn("username: admin");
1801+
console.warn("password: admin");
1802+
console.warn("\n***************************************************************");
1803+
// create a default user
1804+
this.superUser = {
1805+
name: 'admin',
1806+
password: 'admin',
1807+
};
1808+
this.user = {
1809+
name: 'admin',
1810+
password: 'admin',
1811+
};
1812+
fs.writeFileSync(path.join(this.configDirectory, ".user"), JSON.stringify(this.user, null, 2));
1813+
}
1814+
// warn if we have default credentials
1815+
if (this.user.name == 'admin' && this.user.password == 'admin') {
1816+
console.warn('***************************************************************');
1817+
console.warn('\nHAXcms USER CONFIGURATION FILE HAS DEFAULT CREDENTIALS, change them!!');
1818+
console.warn(`\n${path.join(this.configDirectory, ".user")}`);
1819+
console.warn("\n***************************************************************");
1820+
}
17881821
}
17891822
/**
17901823
* Load a site off the file system with option to create
@@ -2661,7 +2694,7 @@ class HAXCMSClass {
26612694
let refreshToken = req.cookies['haxcms_refresh_token'];
26622695
// if there isn't one then we have to bail hard
26632696
if (!refreshToken) {
2664-
res.send(401);
2697+
res.sendStatus(401);
26652698
}
26662699
// if there is a refresh token then decode it
26672700
let refreshTokenDecoded = this.decodeRefreshToken(refreshToken);
@@ -2681,7 +2714,7 @@ class HAXCMSClass {
26812714
// kick back the end if its invalid
26822715
if (endOnInvalid) {
26832716
res.cookie('haxcms_refresh_token', '1', { maxAge: 1 });
2684-
res.send(401);
2717+
res.sendStatus(401);
26852718
}
26862719
return false;
26872720
}
@@ -2701,7 +2734,7 @@ class HAXCMSClass {
27012734
return true;
27022735
}
27032736
else {
2704-
usr = {};
2737+
let usr = {};
27052738
usr.name = name;
27062739
usr.grantAccess = false;
27072740
// fire custom event for things to respond to as needed
@@ -2734,7 +2767,6 @@ class HAXCMSClass {
27342767
else {
27352768
let usr = {};
27362769
usr.name = name;
2737-
usr.password = pass;
27382770
usr.adminFallback = adminFallback;
27392771
usr.grantAccess = false;
27402772
// fire custom event for things to respond to as needed

0 commit comments

Comments
 (0)