diff --git a/README.md b/README.md index 787dec780..46a7eafe2 100644 --- a/README.md +++ b/README.md @@ -77,9 +77,9 @@ Inspired by [Jellyfin](https://jellyfin.org/), allows you to manage all your gam Docker should be installed and set up before running the [image](https://hub.docker.com/r/zurdi15/romm/tags). -1. Generate an API key for [IGDB](https://www.igdb.com/), and set the `CLIENT_ID` and `CLIENT_SECRET` variables. _This is required to run a library scan._ Instructions on generating the ID and Secret are [here](https://api-docs.igdb.com/#about). Note that IDGB requires a Twitch account with 2FA enabled to generate the ID and Secret. +1. Generate an API key for [IGDB](https://www.igdb.com/), and set the `IGDB_CLIENT_ID` and `IGDB_CLIENT_SECRET` variables. _This is required to run a library scan._ Instructions on generating the ID and Secret are [here](https://api-docs.igdb.com/#about). Note that IDGB requires a Twitch account with 2FA enabled to generate the ID and Secret. 2. Verify that your library folder structure matches one of the options listed in the [following section](#folder-structure). -3. Create a docker-compose file. See the following example [docker-compose.yml](https://github.com/zurdi15/romm/blob/master/examples/docker-compose.example.yml) file for reference. Customize for your setup and include the `CLIENT_ID` and `CLIENT_SECRET` vareiables where indicated in the environment section of the file. +3. Create a docker-compose file. See the following example [docker-compose.yml](https://github.com/zurdi15/romm/blob/master/examples/docker-compose.example.yml) file for reference. Customize for your setup and include the `IGDB_CLIENT_ID` and `IGDB_CLIENT_SECRET` vareiables where indicated in the environment section of the file. 4. Launch the container: ```bash diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000..399020d0f --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,21 @@ +Thanks for helping make RomM safer for everyone. + +## Reporting Security Issues + +If you believe you have found a security vulnerability in RomM, please report it to us through coordinated disclosure. + +**Do not report security vulnerabilities through public GitHub issues, discussions, pull requests, or on our public Discord server.** + +Instead, use the [vulnerability report form](https://github.com/zurdi15/romm/security/advisories/new) on GitHub. + +Please include as much of the information listed below as you can to help us better understand and resolve the issue: + +- The type of issue (e.g., permission bypass, remote code execution, etc.) +- Full paths of source file(s) related to the manifestation of the issue +- The location of the affected source code (tag/branch/commit or direct URL) +- Any special configuration required to reproduce the issue +- Step-by-step instructions to reproduce the issue +- Proof-of-concept or exploit code (if possible) +- Impact of the issue (including how an attacker might exploit the issue) + +This information will help us investigate and patch the issue more quickly. diff --git a/backend/config/__init__.py b/backend/config/__init__.py index abe30fcbb..521652225 100644 --- a/backend/config/__init__.py +++ b/backend/config/__init__.py @@ -37,13 +37,19 @@ DB_PASSWD: Final = os.environ.get("DB_PASSWD") DB_NAME: Final = os.environ.get("DB_NAME", "romm") # REDIS -ENABLE_EXPERIMENTAL_REDIS: Final = os.environ.get("ENABLE_EXPERIMENTAL_REDIS", "false") == "true" +ENABLE_EXPERIMENTAL_REDIS: Final = ( + os.environ.get("ENABLE_EXPERIMENTAL_REDIS", "false") == "true" +) REDIS_HOST: Final = os.environ.get("REDIS_HOST", "localhost") REDIS_PORT: Final = os.environ.get("REDIS_PORT", "6379") # IGDB -CLIENT_ID: Final = os.environ.get("CLIENT_ID", "") -CLIENT_SECRET: Final = os.environ.get("CLIENT_SECRET", "") +IGDB_CLIENT_ID: Final = os.environ.get( + "IGDB_CLIENT_ID", os.environ.get("CLIENT_ID", "") +) +IGDB_CLIENT_SECRET: Final = os.environ.get( + "IGDB_CLIENT_SECRET", os.environ.get("CLIENT_SECRET", "") +) # STEAMGRIDDB STEAMGRIDDB_API_KEY: Final = os.environ.get("STEAMGRIDDB_API_KEY", "") diff --git a/backend/endpoints/identity.py b/backend/endpoints/identity.py index ad98b70be..20f1e8bfd 100644 --- a/backend/endpoints/identity.py +++ b/backend/endpoints/identity.py @@ -134,7 +134,6 @@ def update_user( status_code=400, detail="Cannot update user: ROMM_AUTH_ENABLED is set to False", ) - print(form_data.username) user = dbh.get_user(user_id) if not user: raise HTTPException(status_code=404, detail="User not found") diff --git a/backend/endpoints/scan.py b/backend/endpoints/scan.py index bd00c6561..62a19342f 100644 --- a/backend/endpoints/scan.py +++ b/backend/endpoints/scan.py @@ -3,14 +3,14 @@ import socketio # type: ignore from rq import Queue from logger.logger import log -from config import ENABLE_EXPERIMENTAL_REDIS from utils import fs, fastapi from exceptions.fs_exceptions import PlatformsNotFoundException, RomsNotFoundException from handler import dbh from utils.socket import socket_server -from utils.cache import redis_client, redis_url, redis_connectable +from utils.cache import redis_client, redis_url from endpoints.platform import PlatformSchema from endpoints.rom import RomSchema +from config import ENABLE_EXPERIMENTAL_REDIS scan_queue = Queue(connection=redis_client) @@ -21,7 +21,7 @@ async def scan_platforms( # Connect to external socketio server sm = ( socketio.AsyncRedisManager(redis_url, write_only=True) - if redis_connectable + if ENABLE_EXPERIMENTAL_REDIS else socket_server ) @@ -89,7 +89,7 @@ async def scan_handler(_sid: str, options: dict): selected_roms = options.get("roms", []) # Run in worker if redis is available - if redis_connectable and ENABLE_EXPERIMENTAL_REDIS: + if ENABLE_EXPERIMENTAL_REDIS: return scan_queue.enqueue( scan_platforms, platform_slugs, complete_rescan, selected_roms ) diff --git a/backend/handler/igdb_handler.py b/backend/handler/igdb_handler.py index 8a8486a03..4f9fe5b44 100644 --- a/backend/handler/igdb_handler.py +++ b/backend/handler/igdb_handler.py @@ -8,7 +8,7 @@ from unidecode import unidecode as uc from requests.exceptions import HTTPError, Timeout from typing import Final -from config import CLIENT_ID, CLIENT_SECRET +from config import IGDB_CLIENT_ID, IGDB_CLIENT_SECRET from utils import get_file_name_with_no_tags as get_search_term from logger.logger import log from utils.cache import cache @@ -29,7 +29,7 @@ class IGDBHandler: self.screenshots_url = "https://api.igdb.com/v4/screenshots/" self.twitch_auth = TwitchAuth() self.headers = { - "Client-ID": CLIENT_ID, + "Client-ID": IGDB_CLIENT_ID, "Authorization": f"Bearer {self.twitch_auth.get_oauth_token()}", "Accept": "application/json", } @@ -49,9 +49,23 @@ class IGDBHandler: try: res = requests.post(url, data, headers=self.headers, timeout=timeout) res.raise_for_status() + return res.json() except (HTTPError, Timeout) as err: + if err.response.status_code != 401: + log.error(err) + return [] # All requests to the IGDB API return a list + + # Attempt to force a token refresh if the token is invalid + log.warning("Twitch token invalid: fetching a new one...") + token = self.twitch_auth._update_twitch_token() + self.headers["Authorization"] = f"Bearer {token}" + + try: + res = requests.post(url, data, headers=self.headers, timeout=timeout) + res.raise_for_status() + except (HTTPError, Timeout) as err: + # Log the error and return an empty list if the request fails again log.error(err) - # All requests to the IGDB API return a list return [] return res.json() @@ -206,8 +220,8 @@ class TwitchAuth: res = requests.post( url="https://id.twitch.tv/oauth2/token", params={ - "client_id": CLIENT_ID, - "client_secret": CLIENT_SECRET, + "client_id": IGDB_CLIENT_ID, + "client_secret": IGDB_CLIENT_SECRET, "grant_type": "client_credentials", }, timeout=30, diff --git a/backend/utils/cache.py b/backend/utils/cache.py index 15b8252fb..461850682 100644 --- a/backend/utils/cache.py +++ b/backend/utils/cache.py @@ -1,15 +1,10 @@ -from redis import Redis, ConnectionError +from redis import Redis -from config import REDIS_HOST, REDIS_PORT +from config import REDIS_HOST, REDIS_PORT, ENABLE_EXPERIMENTAL_REDIS redis_client = Redis(host=REDIS_HOST, port=int(REDIS_PORT), db=0) redis_url = f"redis://{REDIS_HOST}:{REDIS_PORT}" -try: - redis_connectable = redis_client.ping() -except ConnectionError: - redis_connectable = False - class FallbackCache: def __init__(self) -> None: @@ -42,4 +37,4 @@ _cache_client = Redis( host=REDIS_HOST, port=int(REDIS_PORT), db=0, decode_responses=True ) _fallback_cache = FallbackCache() -cache = _cache_client if redis_connectable else _fallback_cache +cache = _cache_client if ENABLE_EXPERIMENTAL_REDIS else _fallback_cache diff --git a/backend/utils/socket.py b/backend/utils/socket.py index db7b4381c..f5c0f8bc1 100644 --- a/backend/utils/socket.py +++ b/backend/utils/socket.py @@ -1,6 +1,7 @@ import socketio # type: ignore -from utils.cache import redis_url, redis_connectable +from utils.cache import redis_url +from config import ENABLE_EXPERIMENTAL_REDIS socket_server = socketio.AsyncServer( @@ -8,7 +9,9 @@ socket_server = socketio.AsyncServer( async_mode="asgi", logger=False, engineio_logger=False, - client_manager=socketio.AsyncRedisManager(redis_url) if redis_connectable else None, + client_manager=socketio.AsyncRedisManager(redis_url) + if ENABLE_EXPERIMENTAL_REDIS + else None, ) socket_app = socketio.ASGIApp(socket_server) diff --git a/backend/worker.py b/backend/worker.py index a7c6f5a56..cef4e5fa3 100755 --- a/backend/worker.py +++ b/backend/worker.py @@ -2,13 +2,13 @@ import sys from rq import Worker, Queue, Connection from config import ENABLE_EXPERIMENTAL_REDIS -from utils.cache import redis_client, redis_connectable +from utils.cache import redis_client listen = ["high", "default", "low"] if __name__ == "__main__": - # Exit if Redis is not connectable - if not redis_connectable or not ENABLE_EXPERIMENTAL_REDIS: + # Exit if Redis is not enabled + if not ENABLE_EXPERIMENTAL_REDIS: sys.exit(0) with Connection(redis_client): diff --git a/env.template b/env.template index 11fb92e74..e96bc0549 100644 --- a/env.template +++ b/env.template @@ -2,8 +2,8 @@ ROMM_BASE_PATH=/path/to/romm_mock VITE_BACKEND_DEV_PORT=5000 # IGDB credentials -CLIENT_ID= -CLIENT_SECRET= +IGDB_CLIENT_ID= +IGDB_CLIENT_SECRET= # STEAMGRIDDB API key STEAMGRIDDB_API_KEY= diff --git a/examples/docker-compose.example.yml b/examples/docker-compose.example.yml index b560718f7..c7e24eb7d 100644 --- a/examples/docker-compose.example.yml +++ b/examples/docker-compose.example.yml @@ -1,4 +1,4 @@ -version: '3' +version: "3" volumes: mysql_data: services: @@ -6,52 +6,58 @@ services: image: zurdi15/romm:latest container_name: romm environment: - - ROMM_DB_DRIVER=mariadb # mariadb | sqlite (defaults to sqlite) - - DB_HOST=mariadb # [Optional] - - DB_PORT=3306 # [Optional] - - DB_USER=romm-user # [Optional] - - DB_NAME=romm # [Optional] Should match the MYSQL_DATABASE value in the mariadb container - - DB_PASSWD= # [Optional] - # - REDIS_HOST=redis # [Optional] Enables running long tasks (full rescans) in the background - # - REDIS_PORT=6379 # [Optional] - - CLIENT_ID= # [Optional] Required to fetch metadata from IGDB - - CLIENT_SECRET= # [Optional] - - STEAMGRIDDB_API_KEY= # [Optional] Only needed if you want to use SteamGridDB as a source for covers - - ROMM_AUTH_ENABLED=true # [Optional] Will enable user management and require authentication to access the interface (default to false) - - ROMM_AUTH_SECRET_KEY= # [Optional]/[Mandatory if ROMM_AUTH_ENABLED=true] Used to encrypt user passwords, generate one with `openssl rand -hex 32` - - ROMM_AUTH_USERNAME=admin # [Optional] Username for default admin user - - ROMM_AUTH_PASSWORD= # [Optional] Password for default admin user (defaults to admin) + - ROMM_DB_DRIVER=mariadb # mariadb | sqlite (default: sqlite) + # [Optional] Only required if using MariaDB as the database + - DB_HOST=mariadb + - DB_PORT=3306 + - DB_USER=romm-user + - DB_NAME=romm # Should match the MYSQL_DATABASE value in the mariadb container + - DB_PASSWD= + # [Optional] Used to fetch metadata from IGDB + - IGDB_CLIENT_ID= + - IGDB_CLIENT_SECRET= + # [Optional] Use SteamGridDB as a source for covers + - STEAMGRIDDB_API_KEY= + # [Optional] Will enable user management and require authentication to access the interface (default to false) + - ROMM_AUTH_ENABLED=true # default: false + - ROMM_AUTH_SECRET_KEY= # Generate a key with `openssl rand -hex 32` + - ROMM_AUTH_USERNAME=admin # default: admin + - ROMM_AUTH_PASSWORD= # default: admin + # [Optional] Only required if authentication is enabled + - ENABLE_EXPERIMENTAL_REDIS=true # default: false + - REDIS_HOST=redis # default: localhost + - REDIS_PORT=6379 # default: 6379 volumes: - - '/path/to/library:/romm/library' - - '/path/to/resources:/romm/resources' # [Optional] Path where roms metadata (covers) are stored - - '/path/to/config.yml:/romm/config.yml' # [Optional] Path where config is stored - - '/path/to/database:/romm/database' # [Optional] Only needed if ROMM_DB_DRIVER=sqlite or ROMM_DB_DRIVER not exists - - '/path/to/logs:/romm/logs' # [Optional] Path where RomM logs are stored + - "/path/to/library:/romm/library" + - "/path/to/resources:/romm/resources" # [Optional] Path where roms metadata (covers) are stored + - "/path/to/config.yml:/romm/config.yml" # [Optional] Path where config is stored + - "/path/to/database:/romm/database" # [Optional] Only needed if ROMM_DB_DRIVER=sqlite or not set + - "/path/to/logs:/romm/logs" # [Optional] Path where logs are stored ports: - 80:80 depends_on: - romm_db restart: "unless-stopped" - # [Optional] Only needed if ROMM_DB_DRIVER=mariadb + # [Optional] Only required if using MariaDB as the database mariadb: image: mariadb:latest container_name: mariadb environment: - - MYSQL_ROOT_PASSWORD=RootPasswordChangeMe + - MYSQL_ROOT_PASSWORD= - MYSQL_DATABASE=romm - MYSQL_USER=romm-user - - MYSQL_PASSWORD=change-me + - MYSQL_PASSWORD= volumes: - - mysql_data:/var/lib/mysql # Can also be mounted locally if preferred + - mysql_data:/var/lib/mysql # Can also be mounted locally ports: - 3306:3306 restart: "unless-stopped" - # [Optional][Experimental] - # redis: - # image: redis:alpine - # container_name: redis - # restart: unless-stopped - # ports: - # - 6379:6379 + # [Optional] Only required if experimental Redis is enabled + redis: + image: redis:alpine + container_name: redis + restart: unless-stopped + ports: + - 6379:6379 diff --git a/frontend/src/App.vue b/frontend/src/App.vue index b5ca8aafe..67de1337b 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,20 +1,20 @@