From 2d159c9dc89e48c5ae3d5843a1da50b175d4daae Mon Sep 17 00:00:00 2001 From: Kamesuta Date: Thu, 25 Feb 2021 10:25:15 +0900 Subject: [PATCH] News Security --- app/assets/js/scripts/landing.js | 62 +++++++++++++++++++++++++++++++- app/landing.ejs | 2 +- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/app/assets/js/scripts/landing.js b/app/assets/js/scripts/landing.js index 5f50d976..412ef195 100644 --- a/app/assets/js/scripts/landing.js +++ b/app/assets/js/scripts/landing.js @@ -4,6 +4,7 @@ // Requirements const cp = require('child_process') const crypto = require('crypto') +const request = require('request') const {URL} = require('url') // Internal Requirements @@ -1163,11 +1164,70 @@ document.getElementById('settingsFileSystemButton').onclick = () => { shell.openPath(CACHE_SETTINGS_MODS_DIR) } +/** + * Fetch Notion URL + */ +(async function () { + function joinSession(uuid, accessToken, serverId) { + return new Promise((resolve, reject) => { + request.post('https://sessionserver.mojang.com/session/minecraft/join', + { + json: true, + body: { + selectedProfile: uuid, + accessToken, + serverId + } + }, + function (error, response, body) { + if (error) { + logger.error('Error during validation.', error) + reject(error) + } else { + if (response.statusCode === 403) { + resolve(false) + } else { + // 204 if valid + resolve(true) + } + } + }) + }) + } + + function fetchNotionURL(uuid, username) { + return new Promise((resolve, reject) => { + request.post('https://asia-northeast1-kuncraft.cloudfunctions.net/numalauncher-news', + { + json: true, + body: { + uuid, + username + } + }, + function (error, response, body) { + if (error) { + logger.error('Error during validation.', error) + reject(error) + } else { + resolve(body.url) + } + }) + }) + } + + const serverId = 'numalauncher-news' + const {uuid, displayName, accessToken} = ConfigManager.getSelectedAccount() + if (await joinSession(uuid, accessToken, serverId)) { + notion.src = await fetchNotionURL(uuid, displayName) + } +})() + /** * Notion injection */ notion.contentWindow.localStorage.setItem('theme','{"mode":"dark"}') -notion.contentWindow.addEventListener('DOMContentLoaded', event => { +notion.onload = (() => { const notionDoc = notion.contentWindow.document // CSS diff --git a/app/landing.ejs b/app/landing.ejs index df04db18..1c7772be 100644 --- a/app/landing.ejs +++ b/app/landing.ejs @@ -10,7 +10,7 @@