8000 Permissions by brunnre8 · Pull Request #4373 · thelounge/thelounge · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Permissions #4373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,34 @@ function setHome(newPath) {
// Load theme color from the web manifest
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
this.config.themeColor = manifest.theme_color;

// log dir probably shouldn't be world accessible.
// Create it with the desired permission bits if it doesn't exist yet.
let logsStat = undefined;

try {
logsStat = fs.statSync(userLogsPath);
} catch {
// ignored on purpose, node v14.17.0 will give us {throwIfNoEntry: false}
}

if (!logsStat) {
try {
fs.mkdirSync(userLogsPath, {recursive: true, mode: 0o750});
} catch (e) {
log.error("Unable to create logs directory", e);
}
} else if (logsStat && logsStat.mode & 0o001) {
log.warn(
"contents of",
userLogsPath,
"can be accessed by any user, the log files may be exposed"
);

if (os.platform() !== "win32") {
log.warn(`run \`chmod o-x ${userLogsPath}\` to correct it`);
}
}
}

function getHomePath() {
Expand Down
27 changes: 25 additions & 2 deletions src/plugins/webpush.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,28 @@ class WebPush {
constructor() {
const vapidPath = path.join(Helper.getHomePath(), "vapid.json");

if (fs.existsSync(vapidPath)) {
let vapidStat = undefined;

try {
vapidStat = fs.statSync(vapidPath);
} catch {
// ignored on purpose, node v14.17.0 will give us {throwIfNoEntry: false}
}

if (vapidStat) {
const isWorldReadable = (vapidStat.mode & 0o004) !== 0;

if (isWorldReadable) {
log.warn(
vapidPath,
"is world readable. The file contains secrets. Please fix the permissions"
);

if (require("os").platform() !== "win32") {
log.warn(`run \`chmod o= ${vapidPath}\` to correct it`);
}
}

const data = fs.readFileSync(vapidPath, "utf-8");
const parsedData = JSON.parse(data);

Expand All @@ -29,7 +50,9 @@ class WebPush {
if (!this.vapidKeys) {
this.vapidKeys = WebPushAPI.generateVAPIDKeys();

fs.writeFileSync(vapidPath, JSON.stringify(this.vapidKeys, null, "\t"));
fs.writeFileSync(vapidPath, JSON.stringify(this.vapidKeys, null, "\t"), {
mode: 0o600,
});

log.info("New VAPID key pair has been generated for use with push subscription.");
}
Expand Down
0