Cookie file not generated for BTCPayServer #990 (#994)

Cookie file not generated for BTCPayServer #990
pull/995/head
ShahanaFarooqui 2 years ago committed by GitHub
parent e7faa8c75b
commit ebff40327f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -53,8 +53,7 @@ export const authenticateUser = (req, res, next) => {
res.status(406).json({ message: 'SSO Authentication Error', error: 'Login with Password is not allowed with SSO.' });
}
else if (req.body.authenticateWith === 'PASSWORD') {
const cookieValue = common.readCookie();
if (cookieValue.trim().length >= 32 && crypto.timingSafeEqual(Buffer.from(crypto.createHash('sha256').update(cookieValue).digest('hex'), 'utf-8'), Buffer.from(req.body.authenticationValue, 'utf-8'))) {
if (common.cookie_value.trim().length >= 32 && crypto.timingSafeEqual(Buffer.from(crypto.createHash('sha256').update(common.cookie_value).digest('hex'), 'utf-8'), Buffer.from(req.body.authenticationValue, 'utf-8'))) {
common.refreshCookie();
if (!req.session.selectedNode) {
req.session.selectedNode = common.initSelectedNode;

@ -18,6 +18,7 @@ export class CommonService {
this.rtl_sso = 0;
this.rtl_cookie_path = '';
this.logout_redirect_link = '';
this.cookie_value = '';
this.api_version = '';
this.secret_key = crypto.randomBytes(64).toString('hex');
this.read_dummy_data = false;
@ -282,7 +283,7 @@ export class CommonService {
const exists = fs.existsSync(this.rtl_cookie_path);
if (exists) {
try {
return fs.readFileSync(this.rtl_cookie_path, 'utf-8');
this.cookie_value = fs.readFileSync(this.rtl_cookie_path, 'utf-8');
}
catch (err) {
this.logger.log({ selectedNode: this.initSelectedNode, level: 'ERROR', fileName: 'Config', msg: 'Something went wrong while reading cookie: \n' + err });
@ -294,7 +295,7 @@ export class CommonService {
const directoryName = dirname(this.rtl_cookie_path);
this.createDirectory(directoryName);
fs.writeFileSync(this.rtl_cookie_path, crypto.randomBytes(64).toString('hex'));
return fs.readFileSync(this.rtl_cookie_path, 'utf-8');
this.cookie_value = fs.readFileSync(this.rtl_cookie_path, 'utf-8');
}
catch (err) {
this.logger.log({ selectedNode: this.initSelectedNode, level: 'ERROR', fileName: 'Config', msg: 'Something went wrong while reading the cookie: \n' + err });
@ -305,6 +306,7 @@ export class CommonService {
this.refreshCookie = () => {
try {
fs.writeFileSync(this.rtl_cookie_path, crypto.randomBytes(64).toString('hex'));
this.cookie_value = fs.readFileSync(this.rtl_cookie_path, 'utf-8');
}
catch (err) {
this.logger.log({ selectedNode: this.initSelectedNode, level: 'ERROR', fileName: 'Common', msg: 'Something went wrong while refreshing cookie', error: err });

@ -307,8 +307,13 @@ export class ConfigService {
else if (config.SSO && config.SSO.logoutRedirectLink) {
this.common.logout_redirect_link = config.SSO.logoutRedirectLink;
}
if (+this.common.rtl_sso && (!this.common.rtl_cookie_path || this.common.rtl_cookie_path.trim() === '')) {
this.errMsg = 'Please set rtlCookiePath value for single sign on option!';
if (+this.common.rtl_sso) {
if (!this.common.rtl_cookie_path || this.common.rtl_cookie_path.trim() === '') {
this.errMsg = 'Please set rtlCookiePath value for single sign on option!';
}
else {
this.common.readCookie();
}
}
};
this.setSelectedNode = (config) => {

@ -13,6 +13,6 @@
<style>@font-face{font-family:Roboto;src:url(Roboto-Thin.f7a95c9c5999532c.woff2) format("woff2"),url(Roboto-Thin.c13c157cb81e8ebb.woff) format("woff");font-weight:100;font-style:normal}@font-face{font-family:Roboto;src:url(Roboto-ThinItalic.b0e084abf689f393.woff2) format("woff2"),url(Roboto-ThinItalic.1111028df6cea564.woff) format("woff");font-weight:100;font-style:italic}@font-face{font-family:Roboto;src:url(Roboto-Light.0e01b6cd13b3857f.woff2) format("woff2"),url(Roboto-Light.603ca9a537b88428.woff) format("woff");font-weight:300;font-style:normal}@font-face{font-family:Roboto;src:url(Roboto-LightItalic.232ef4b20215f720.woff2) format("woff2"),url(Roboto-LightItalic.1b5e142f787151c8.woff) format("woff");font-weight:300;font-style:italic}@font-face{font-family:Roboto;src:url(Roboto-Regular.475ba9e4e2d63456.woff2) format("woff2"),url(Roboto-Regular.bcefbfee882bc1cb.woff) format("woff");font-weight:400;font-style:normal}@font-face{font-family:Roboto;src:url(Roboto-RegularItalic.e3a9ebdaac06bbc4.woff2) format("woff2"),url(Roboto-RegularItalic.0668fae6af0cf8c2.woff) format("woff");font-weight:400;font-style:italic}@font-face{font-family:Roboto;src:url(Roboto-Medium.457532032ceb0168.woff2) format("woff2"),url(Roboto-Medium.6e1ae5f0b324a0aa.woff) format("woff");font-weight:500;font-style:normal}@font-face{font-family:Roboto;src:url(Roboto-MediumItalic.872f7060602d55d2.woff2) format("woff2"),url(Roboto-MediumItalic.e06fb533801cbb08.woff) format("woff");font-weight:500;font-style:italic}@font-face{font-family:Roboto;src:url(Roboto-Bold.447291a88c067396.woff2) format("woff2"),url(Roboto-Bold.fc482e6133cf5e26.woff) format("woff");font-weight:700;font-style:normal}@font-face{font-family:Roboto;src:url(Roboto-BoldItalic.1b15168ef6fa4e16.woff2) format("woff2"),url(Roboto-BoldItalic.e26ba339b06f09f7.woff) format("woff");font-weight:700;font-style:italic}@font-face{font-family:Roboto;src:url(Roboto-Black.2eaa390d458c877d.woff2) format("woff2"),url(Roboto-Black.b25f67ad8583da68.woff) format("woff");font-weight:900;font-style:normal}@font-face{font-family:Roboto;src:url(Roboto-BlackItalic.7dc03ee444552bc5.woff2) format("woff2"),url(Roboto-BlackItalic.c8dc642467cb3099.woff) format("woff");font-weight:900;font-style:italic}html{width:100%;height:99%;line-height:1.5;overflow-x:hidden;font-family:Roboto,sans-serif!important;font-size:62.5%}body{box-sizing:border-box;height:100%;margin:0;overflow:hidden}*{margin:0;padding:0}</style><link rel="stylesheet" href="styles.30265dd456248897.css" media="print" onload="this.media='all'"><noscript><link rel="stylesheet" href="styles.30265dd456248897.css"></noscript></head>
<body>
<rtl-app></rtl-app>
<script src="runtime.f93fe30ac25690b5.js" type="module"></script><script src="polyfills.c0773154203456c6.js" type="module"></script><script src="main.8a6a8aab46b095f7.js" type="module"></script>
<script src="runtime.f93fe30ac25690b5.js" type="module"></script><script src="polyfills.c0773154203456c6.js" type="module"></script><script src="main.5caebb50f283ae1b.js" type="module"></script>
</body></html>

File diff suppressed because one or more lines are too long

2124
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,6 +1,6 @@
{
"name": "rtl",
"version": "0.12.2-beta",
"version": "0.12.3-beta",
"license": "MIT",
"type": "module",
"scripts": {
@ -64,7 +64,7 @@
},
"devDependencies": {
"@angular-devkit/build-angular": "^13.0.3",
"@angular-eslint/builder": "13.0.1",
"@angular-eslint/builder": "^12.2.1",
"@angular-eslint/eslint-plugin": "13.0.1",
"@angular-eslint/eslint-plugin-template": "13.0.1",
"@angular-eslint/schematics": "13.0.1",

@ -56,8 +56,7 @@ export const authenticateUser = (req, res, next) => {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'User Authenticated' });
res.status(406).json({ message: 'SSO Authentication Error', error: 'Login with Password is not allowed with SSO.' });
} else if (req.body.authenticateWith === 'PASSWORD') {
const cookieValue = common.readCookie();
if (cookieValue.trim().length >= 32 && crypto.timingSafeEqual(Buffer.from(crypto.createHash('sha256').update(cookieValue).digest('hex'), 'utf-8'), Buffer.from(req.body.authenticationValue, 'utf-8'))) {
if (common.cookie_value.trim().length >= 32 && crypto.timingSafeEqual(Buffer.from(crypto.createHash('sha256').update(common.cookie_value).digest('hex'), 'utf-8'), Buffer.from(req.body.authenticationValue, 'utf-8'))) {
common.refreshCookie();
if (!req.session.selectedNode) { req.session.selectedNode = common.initSelectedNode; }
const token = jwt.sign({ user: 'SSO_USER' }, common.secret_key);

@ -20,6 +20,7 @@ export class CommonService {
public rtl_sso = 0;
public rtl_cookie_path = '';
public logout_redirect_link = '';
public cookie_value = '';
public api_version = '';
public secret_key = crypto.randomBytes(64).toString('hex');
public read_dummy_data = false;
@ -300,7 +301,7 @@ export class CommonService {
const exists = fs.existsSync(this.rtl_cookie_path);
if (exists) {
try {
return fs.readFileSync(this.rtl_cookie_path, 'utf-8');
this.cookie_value = fs.readFileSync(this.rtl_cookie_path, 'utf-8');
} catch (err) {
this.logger.log({ selectedNode: this.initSelectedNode, level: 'ERROR', fileName: 'Config', msg: 'Something went wrong while reading cookie: \n' + err });
throw new Error(err);
@ -310,7 +311,7 @@ export class CommonService {
const directoryName = dirname(this.rtl_cookie_path);
this.createDirectory(directoryName);
fs.writeFileSync(this.rtl_cookie_path, crypto.randomBytes(64).toString('hex'));
return fs.readFileSync(this.rtl_cookie_path, 'utf-8');
this.cookie_value = fs.readFileSync(this.rtl_cookie_path, 'utf-8');
} catch (err) {
this.logger.log({ selectedNode: this.initSelectedNode, level: 'ERROR', fileName: 'Config', msg: 'Something went wrong while reading the cookie: \n' + err });
throw new Error(err);
@ -321,6 +322,7 @@ export class CommonService {
public refreshCookie = () => {
try {
fs.writeFileSync(this.rtl_cookie_path, crypto.randomBytes(64).toString('hex'));
this.cookie_value = fs.readFileSync(this.rtl_cookie_path, 'utf-8');
} catch (err) {
this.logger.log({ selectedNode: this.initSelectedNode, level: 'ERROR', fileName: 'Common', msg: 'Something went wrong while refreshing cookie', error: err });
throw new Error(err);

@ -287,8 +287,12 @@ export class ConfigService {
this.common.logout_redirect_link = config.SSO.logoutRedirectLink;
}
if (+this.common.rtl_sso && (!this.common.rtl_cookie_path || this.common.rtl_cookie_path.trim() === '')) {
this.errMsg = 'Please set rtlCookiePath value for single sign on option!';
if (+this.common.rtl_sso) {
if (!this.common.rtl_cookie_path || this.common.rtl_cookie_path.trim() === '') {
this.errMsg = 'Please set rtlCookiePath value for single sign on option!';
} else {
this.common.readCookie();
}
}
};

@ -26,4 +26,4 @@ export const environment = {
Web_SOCKET_API: '/ws'
};
export const VERSION = '0.12.2-beta';
export const VERSION = '0.12.3-beta';

@ -26,4 +26,4 @@ export const environment = {
Web_SOCKET_API: '/ws'
};
export const VERSION = '0.12.2-beta';
export const VERSION = '0.12.3-beta';

Loading…
Cancel
Save