Skip to content

Commit b537ada

Browse files
committed
Critical security bug fixes and stability improvements
- Critical socket.io security vulnerabilities patched - Improved collector handling of client errors, such as 504 (will no longer treat as "empty" response and remove all previously fetched items for that client) - Client timeouts are now appropriately caught and logged, will no longer bring down Shelf instance. - Renamed `ShelfProperties` to `PropertyManager`, for clarity - All rogue tabs now converted to x4 spaces - No longer attempting to load missing `Logger.js` file client-side - Trimmed unused require statements - Improved names in paths.js - Refactored mongoCleaner.js to be consistent with Shelf style guide - Rewrote some documentation - Rewrote MongoClient.js logging statements to be more helpful, consistent, and clear
1 parent e388396 commit b537ada

30 files changed

+1045
-5810
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,5 @@ typings/
6363
/client/static/images/board-games/boardgame*
6464
/server/config.json
6565
/replacement-art
66+
/fix
67+
package-lock.json

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
<img src="https://raw.githubusercontent.com/barrowclift/shelf/master/screenshots/shelf-promo.png" />
88

99
1. [FAQ](#faq)
10-
* [Why use shelf?](#why-use-shelf)
11-
* [Doesn't Discogs/Goodreads/BoardGameGeek already do this?](#doesnt-discogsgoodreadsboardgamegeek-already-do-this)
12-
* [How does Shelf handle different issues of the same entity?](#how-does-shelf-handle-different-issues-of-the-same-entity)
13-
* [Can I help?](#can-i-help)
10+
* [Why use shelf?](#why-use-shelf)
11+
* [Doesn't Discogs/Goodreads/BoardGameGeek already do this?](#doesnt-discogsgoodreadsboardgamegeek-already-do-this)
12+
* [How does Shelf handle different issues of the same entity?](#how-does-shelf-handle-different-issues-of-the-same-entity)
13+
* [Can I help?](#can-i-help)
1414
2. [Setup](#setup)
15-
* [Installation](#installation)
16-
* [v1 Migration](#v1x-migration)
17-
* [How do I add my library to Shelf?](#how-do-i-add-my-library-to-shelf)
18-
* [How do I sync my Discogs account with Shelf to display my records?](#how-do-i-sync-my-discogs-account-with-shelf-to-display-my-records)
19-
* [How do I sync my Goodreads account with Shelf to display my books?](#how-do-i-sync-my-goodreads-account-with-shelf-to-display-my-books)
20-
* [How do I sync my BoardGameGeek account with Shelf to display my games?](#how-do-i-sync-my-boardgamegeek-account-with-shelf-to-display-my-games)
21-
* [Can I add new entities into Shelf directly?](#can-i-add-new-entities-into-shelf-directly)
22-
* [What if I only want to display a particular collection, like board games?](#what-if-i-only-want-to-display-a-particular-collection-like-board-games)
15+
* [Installation](#installation)
16+
* [v1 Migration](#v1x-migration)
17+
* [How do I add my library to Shelf?](#how-do-i-add-my-library-to-shelf)
18+
* [How do I sync my Discogs account with Shelf to display my records?](#how-do-i-sync-my-discogs-account-with-shelf-to-display-my-records)
19+
* [How do I sync my Goodreads account with Shelf to display my books?](#how-do-i-sync-my-goodreads-account-with-shelf-to-display-my-books)
20+
* [How do I sync my BoardGameGeek account with Shelf to display my games?](#how-do-i-sync-my-boardgamegeek-account-with-shelf-to-display-my-games)
21+
* [Can I add new entities into Shelf directly?](#can-i-add-new-entities-into-shelf-directly)
22+
* [What if I only want to display a particular collection, like board games?](#what-if-i-only-want-to-display-a-particular-collection-like-board-games)
2323
3. [Architecture](#architecture)
2424
3. [Roadmap](#roadmap)
25-
* [Do you plan to later support other media in Shelf, like Video Games and Movies?](#do-you-plan-to-later-support-other-media-in-shelf-like-video-games-and-movies)
26-
* ["X doesn't look right in Firefox/Chrome/Opera, will you fix it?"](#x-doesnt-look-right-in-firefoxchromeopera-will-you-fix-it)
25+
* [Do you plan to later support other media in Shelf, like Video Games and Movies?](#do-you-plan-to-later-support-other-media-in-shelf-like-video-games-and-movies)
26+
* ["X doesn't look right in Firefox/Chrome/Opera, will you fix it?"](#x-doesnt-look-right-in-firefoxchromeopera-will-you-fix-it)
2727

2828
# FAQ
2929

admin/cleanMongoDb.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function cleanMongoDb {
2929
wait $starterProcess
3030
fi
3131

32-
node "${ADMIN_DIR}"/mongoCleaner.js > "${LOGS_DIR}"/clean-mongodb.log 2>&1 &
32+
node "${ADMIN_DIR}"/mongoShim.js "clean" > "${LOGS_DIR}"/clean-mongodb.log 2>&1 &
3333
cleanerProcess=$!
3434
wait $cleanerProcess
3535

admin/dropCache.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
export ADMIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
4+
source "${ADMIN_DIR}"/init.sh
5+
6+
function dropCache {
7+
node "${ADMIN_DIR}"/mongoShim.js "clear" > "${LOGS_DIR}"/drop-cache.log 2>&1 &
8+
dropCacheProcess=$!
9+
wait $dropCacheProcess
10+
11+
echo "Shelf cache has been dropped"
12+
}
13+
14+
dropCache
15+
16+
exit 0

admin/mongoCleaner.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

admin/mongoShim.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"use strict";
2+
3+
// DEPENDENCIES
4+
// ------------
5+
// External
6+
let path = require("path");
7+
let Properties = require("properties");
8+
let request = require("request-promise");
9+
let socketIo = require("socket.io-client");
10+
// Local
11+
const SHELF_ROOT_DIRECTORY_PATH = path.join(__dirname, "..");
12+
let CachedMongoClient = require(path.join(SHELF_ROOT_DIRECTORY_PATH, "server/db/CachedMongoClient"));
13+
let PropertyManager = require(path.join(SHELF_ROOT_DIRECTORY_PATH, "server/common/PropertyManager"));
14+
let socketCodes = require(path.join(SHELF_ROOT_DIRECTORY_PATH, "server/common/socketCodes"));
15+
let util = require(path.join(SHELF_ROOT_DIRECTORY_PATH, "server/common/util"));
16+
17+
18+
// CONSTANTS
19+
// ---------
20+
const PROPERTIES_FILE_NAME = path.join(SHELF_ROOT_DIRECTORY_PATH, "server/resources/shelf.properties");
21+
22+
23+
// GLOBALS
24+
// -------
25+
var propertyManager = null;
26+
27+
28+
async function cleanDbAndClose() {
29+
var mongoClient = new CachedMongoClient(propertyManager);
30+
await mongoClient.connect();
31+
await mongoClient.dropRecords();
32+
await mongoClient.dropBoardGames();
33+
await mongoClient.dropBooks();
34+
await mongoClient.close();
35+
}
36+
37+
async function sendClearCacheRequest() {
38+
// Connect to backend server for communicating changes
39+
let backendSocket = socketIo.connect(propertyManager.backendUrl, { reconnect: true });
40+
let messageSent = false;
41+
backendSocket.on("connect", function() {
42+
console.log("Socket connection to backend server initialized");
43+
backendSocket.emit(socketCodes.CLEAR_CACHE);
44+
messageSent = true;
45+
});
46+
while (!messageSent) {
47+
await util.sleepForSeconds(0.1);
48+
}
49+
backendSocket.close();
50+
}
51+
52+
async function main() {
53+
propertyManager = new PropertyManager();
54+
await propertyManager.load(PROPERTIES_FILE_NAME);
55+
56+
let command = process.argv[2]
57+
if ("clean" == command) {
58+
await cleanDbAndClose();
59+
} else if ("clear" == command) {
60+
await sendClearCacheRequest();
61+
} else {
62+
console.log("Unsupported command '" + command + "'")
63+
}
64+
}
65+
66+
main();

admin/start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ wait $result
3434
SUCCESS=$?
3535

3636
if [ $SUCCESS -eq 0 ]; then
37-
echo -e "${GREEN}All started successfully${RESET}"
37+
echo -e "${GREEN}All started successfully${RESET}"
3838
exit 0
3939
else
4040
echo -e "${RED}Shelf failed to start${RESET}"

admin/startMongoDb.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
export ADMIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
4-
source ${ADMIN_DIR}/init.sh
4+
source "${ADMIN_DIR}"/init.sh
55

66
MONGODB_NOHUP_RUNNING=$(ps -ef | grep "mongod --dbpath ""$MONGO_DB" | grep -v grep)
77
HAS_SERVICE_COMMAND=$(command -v service)

admin/startServer.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
#
2+
33
export ADMIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
44
source "${ADMIN_DIR}"/init.sh
55

admin/stopServer.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ source "${ADMIN_DIR}"/init.sh
66
SERVER_RUNNING=$(ps -ef | grep "node ""${SERVER_DIR}" | grep -v grep)
77

88
if [ -n "$SERVER_RUNNING" ]; then
9-
if [ "$USE_PM2" = true ] ; then
10-
pm2 --silent stop shelf
11-
else
12-
ps -ef | grep "node ""${SERVER_DIR}""/main.js" | grep -v grep | awk '{print $2}' | xargs kill -9
13-
fi
9+
if [ "$USE_PM2" = true ] ; then
10+
pm2 --silent stop shelf
11+
else
12+
ps -ef | grep "node ""${SERVER_DIR}""/main.js" | grep -v grep | awk '{print $2}' | xargs kill -9
13+
fi
1414

1515
SUCCESS=$?
1616
if [ $SUCCESS -eq 0 ]; then

0 commit comments

Comments
 (0)