Skip to content

Commit

Permalink
adding code quality scanning;
Browse files Browse the repository at this point in the history
npm package updates
  • Loading branch information
reZach committed Oct 2, 2020
1 parent 9144982 commit 561d81b
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 34 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# secure-electron-template
A current electron app template with the most popular frameworks, designed and built with security in mind. (If you are curious about what makes an electron app secure, please check out [this page](https://github.com/reZach/secure-electron-template/blob/master/docs/secureapps.md)).

[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=reZach_secure-electron-template&metric=security_rating)](https://sonarcloud.io/dashboard?id=reZach_secure-electron-template)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=reZach_secure-electron-template&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=reZach_secure-electron-template)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=reZach_secure-electron-template&metric=bugs)](https://sonarcloud.io/dashboard?id=reZach_secure-electron-template)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=reZach_secure-electron-template&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=reZach_secure-electron-template)


![Banner](https://github.com/reZach/secure-electron-template/blob/master/docs/imgs/banner-image.png "Banner")

_Banner built with [banner-maker](https://github.com/banner-maker/banner-maker)!_
Expand Down
24 changes: 12 additions & 12 deletions app/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ async function createWindow() {

// Sets up main.js bindings for our electron store;
// callback is optional and allows you to use store in main process
const callback = function (success, store) {
const callback = function (success, initialStore) {
console.log(`${!success ? "Un-s" : "S"}uccessfully retrieved store in main process.`);
console.log(store); // {"key1": "value1", ... }
console.log(initialStore); // {"key1": "value1", ... }
};

store.mainBindings(ipcMain, win, fs, callback);
Expand Down Expand Up @@ -116,17 +116,17 @@ async function createWindow() {
const partition = "default";
ses
.fromPartition(partition)
.setPermissionRequestHandler((webContents, permission, callback) => {
.setPermissionRequestHandler((webContents, permission, permCallback) => {
let allowedPermissions = []; // Full list here: https://developer.chrome.com/extensions/declare_permissions#manifest

if (allowedPermissions.includes(permission)) {
callback(true); // Approve permission request
permCallback(true); // Approve permission request
} else {
console.error(
`The application tried to request permission for '${permission}'. This permission was not whitelisted and has been blocked.`
);

callback(false); // Deny
permCallback(false); // Deny
}
});

Expand Down Expand Up @@ -184,7 +184,7 @@ app.on("activate", () => {

// https://electronjs.org/docs/tutorial/security#12-disable-or-limit-navigation
app.on("web-contents-created", (event, contents) => {
contents.on("will-navigate", (event, navigationUrl) => {
contents.on("will-navigate", (contentsEvent, navigationUrl) => {
const parsedUrl = new URL(navigationUrl);
const validOrigins = [selfHost];

Expand All @@ -194,12 +194,12 @@ app.on("web-contents-created", (event, contents) => {
`The application tried to redirect to the following address: '${parsedUrl}'. This origin is not whitelisted and the attempt to navigate was blocked.`
);

event.preventDefault();
contentsEvent.preventDefault();
return;
}
});

contents.on("will-redirect", (event, navigationUrl) => {
contents.on("will-redirect", (contentsEvent, navigationUrl) => {
const parsedUrl = new URL(navigationUrl);
const validOrigins = [];

Expand All @@ -209,13 +209,13 @@ app.on("web-contents-created", (event, contents) => {
`The application tried to redirect to the following address: '${navigationUrl}'. This attempt was blocked.`
);

event.preventDefault();
contentsEvent.preventDefault();
return;
}
});

// https://electronjs.org/docs/tutorial/security#11-verify-webview-options-before-creation
contents.on("will-attach-webview", (event, webPreferences, params) => {
contents.on("will-attach-webview", (contentsEvent, webPreferences, params) => {
// Strip away preload scripts if unused or verify their location is legitimate
delete webPreferences.preload;
delete webPreferences.preloadURL;
Expand All @@ -225,13 +225,13 @@ app.on("web-contents-created", (event, contents) => {
});

// https://electronjs.org/docs/tutorial/security#13-disable-or-limit-creation-of-new-windows
contents.on("new-window", async (event, navigationUrl) => {
contents.on("new-window", async (contentsEvent, navigationUrl) => {
// Log and prevent opening up a new window
console.error(
`The application tried to open a new window at the following address: '${navigationUrl}'. This attempt was blocked.`
);

event.preventDefault();
contentsEvent.preventDefault();
return;
});
});
Expand Down
2 changes: 1 addition & 1 deletion app/src/core/root.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { ConnectedRouter } from "connected-react-router";
import { Provider, connect } from "react-redux";
import { Provider } from "react-redux";
import Routes from "Core/routes";
import "./root.css";

Expand Down
1 change: 1 addition & 0 deletions app/src/index-prod.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<head>
<meta charset="UTF-8">
<title>My app</title>
<base href="app://rse">
</head>

Expand Down
1 change: 1 addition & 0 deletions app/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<head>
<meta charset="UTF-8">
<title>My app</title>
</head>

<body>
Expand Down
4 changes: 2 additions & 2 deletions app/src/redux/components/complex/complexSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const complexSlice = createSlice({
});
},
remove(state, action) {
let index = Math.floor(Math.random() * state.length);
state.splice(index, 1);
const randIndex = Math.floor(Math.random() * state.length);
state.splice(randIndex, 1);
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions app/src/redux/reducers/rootReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import homeReducer from "../components/home/homeSlice";
import counterReducer from "../components/counter/counterSlice";
import complexReducer from "../components/complex/complexSlice";

const createRootReducer = (history) =>
const rootReducer = (history) =>
combineReducers({
router: connectRouter(history),
home: homeReducer,
Expand All @@ -17,4 +17,4 @@ const createRootReducer = (history) =>
)
});

export default createRootReducer;
export default rootReducer;
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "secure-electron-template",
"version": "5.1.4",
"version": "5.1.5",
"description": "The best way to build Electron apps with security in mind.",
"private": true,
"main": "app/electron/main.js",
Expand Down Expand Up @@ -69,7 +69,7 @@
"cross-env": "^7.0.2",
"csp-html-webpack-plugin": "^4.0.0",
"css-loader": "^3.6.0",
"electron": "^10.1.2",
"electron": "^10.1.3",
"electron-builder": "^22.8.1",
"electron-debug": "^3.1.0",
"electron-devtools-installer": "^3.1.1",
Expand All @@ -93,7 +93,7 @@
"lodash.merge": "^4.6.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-i18next": "^11.7.2",
"react-i18next": "^11.7.3",
"react-redux": "^7.2.1",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
Expand Down

0 comments on commit 561d81b

Please sign in to comment.