Skip to content

🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!

Security: stop error responses disclosing internal hosts, paths, and exception text (CFG-10)

Omega (QA)04713e1af05d
diff --git a/backend/file_routes.py b/backend/file_routes.py
index 1959bcf..f452915 100644
--- a/backend/file_routes.py
+++ b/backend/file_routes.py
@@ -589,11 +589,16 @@ def paperless_search():
response = paperless_handler.get(search_url, params=params, timeout=30)
response.raise_for_status()
except Exception as e:
- # Provide user-friendly error on auth failures
- return jsonify({
- 'success': False,
- 'message': f'Paperless-ngx search failed: {str(e)}'
- }), 400
+ # Log the full error server-side, but never send exception
+ # text to the client: a connection error carries the internal
+ # Paperless host, port, API path, and query shape (CFG-10).
+ logger.error(f"Paperless-ngx search failed: {e}")
+ status = getattr(getattr(e, 'response', None), 'status_code', None)
+ if status in (401, 403):
+ message = 'Paperless-ngx search failed: Paperless-ngx rejected the credentials.'
+ else:
+ message = 'Paperless-ngx search failed. Check that Paperless-ngx is reachable.'
+ return jsonify({'success': False, 'message': message}), 400
search_result = response.json()
logger.info(f"Paperless search returned {len(search_result.get('results', []))} documents")
@@ -613,7 +618,7 @@ def paperless_search():
except Exception as e:
logger.error(f"Error searching Paperless documents: {e}")
- return jsonify({'success': False, 'message': str(e)}), 500
+ return jsonify({'success': False, 'message': 'An error occurred while searching Paperless documents.'}), 500
finally:
if conn:
release_db_connection(conn)
@@ -650,16 +655,25 @@ def paperless_tags():
parts = urlparse(url)
url = parts.path + (('?' + parts.query) if parts.query else '')
except Exception as e:
- return jsonify({'success': False, 'message': f'Paperless-ngx tags failed: {str(e)}'}), 400
+ # See CFG-10 in paperless_search: exception text can carry
+ # the internal Paperless host and path, so log it and reply
+ # with a generic message.
+ logger.error(f"Paperless-ngx tags failed: {e}")
+ status = getattr(getattr(e, 'response', None), 'status_code', None)
+ if status in (401, 403):
+ message = 'Paperless-ngx tags failed: Paperless-ngx rejected the credentials.'
+ else:
+ message = 'Paperless-ngx tags failed. Check that Paperless-ngx is reachable.'
+ return jsonify({'success': False, 'message': message}), 400
tags_result = {'results': all_tags, 'count': len(all_tags)}
logger.info(f"Paperless tags returned {len(all_tags)} tags")
return jsonify(tags_result)
-
+
except Exception as e:
logger.error(f"Error fetching Paperless tags: {e}")
- return jsonify({'success': False, 'message': str(e)}), 500
+ return jsonify({'success': False, 'message': 'An error occurred while fetching Paperless tags.'}), 500
finally:
if conn:
release_db_connection(conn)
diff --git a/backend/statistics_routes.py b/backend/statistics_routes.py
index 38f8068..a05d4d1 100644
--- a/backend/statistics_routes.py
+++ b/backend/statistics_routes.py
@@ -282,7 +282,7 @@ def get_statistics():
except Exception as e:
logger.error(f"Error getting warranty statistics: {e}")
- return jsonify({"error": str(e)}), 500
+ return jsonify({"error": "Failed to load statistics."}), 500
finally:
if conn:
@@ -527,7 +527,7 @@ def get_global_statistics():
except Exception as e:
logger.error(f"Error getting global warranty statistics: {e}")
- return jsonify({"error": str(e)}), 500
+ return jsonify({"error": "Failed to load statistics."}), 500
finally:
if conn:
diff --git a/backend/warranties_routes.py b/backend/warranties_routes.py
index 352b6ef..3edb308 100644
--- a/backend/warranties_routes.py
+++ b/backend/warranties_routes.py
@@ -526,7 +526,7 @@ def add_warranty():
except Exception as e:
logger.error(f"Error saving invoice {filename} to {invoice_path}: {e}")
# Optionally, decide if you want to return an error here or continue
- return jsonify({"error": f"Failed to save invoice: {str(e)}"}), 500
+ return jsonify({"error": "Failed to save invoice."}), 500
elif paperless_invoice_id:
logger.info(f"Invoice stored in Paperless-ngx with ID: {paperless_invoice_id}")
@@ -547,7 +547,7 @@ def add_warranty():
logger.info(f"Successfully saved manual: {db_manual_path}")
except Exception as e:
logger.error(f"Error saving manual {filename} to {manual_path}: {e}")
- return jsonify({"error": f"Failed to save manual: {str(e)}"}), 500
+ return jsonify({"error": "Failed to save manual."}), 500
elif paperless_manual_id:
logger.info(f"Manual stored in Paperless-ngx with ID: {paperless_manual_id}")
@@ -568,7 +568,7 @@ def add_warranty():
logger.info(f"Successfully saved other_document: {db_other_document_path}")
except Exception as e:
logger.error(f"Error saving other_document {filename} to {other_document_path_on_disk}: {e}")
- return jsonify({"error": f"Failed to save other_document: {str(e)}"}), 500
+ return jsonify({"error": "Failed to save other_document."}), 500
elif paperless_other_id:
logger.info(f"Other document stored in Paperless-ngx with ID: {paperless_other_id}")
@@ -590,7 +590,7 @@ def add_warranty():
logger.info(f"Successfully saved product_photo: {db_product_photo_path}")
except Exception as e:
logger.error(f"Error saving product_photo {filename} to {product_photo_path_on_disk}: {e}")
- return jsonify({"error": f"Failed to save product_photo: {str(e)}"}), 500
+ return jsonify({"error": "Failed to save product_photo."}), 500
elif paperless_photo_id:
logger.info(f"Product photo stored in Paperless-ngx with ID: {paperless_photo_id}")
@@ -612,7 +612,7 @@ def add_warranty():
logger.info(f"Successfully saved product_photo from URL: {db_product_photo_path}")
except Exception as e:
logger.error(f"Error saving product_photo from URL {filename}: {e}")
- return jsonify({"error": f"Failed to save product_photo: {str(e)}"}), 500
+ return jsonify({"error": "Failed to save product_photo."}), 500
diff --git a/tests/test_error_disclosure.py b/tests/test_error_disclosure.py
new file mode 100644
index 0000000..6b245a7
--- /dev/null
+++ b/tests/test_error_disclosure.py
@@ -0,0 +1,71 @@
+"""Error responses must not disclose internal detail (CFG-10).
+
+A Paperless connection failure used to reach the client verbatim,
+carrying the internal host, port, API path, and query shape. The full
+error is still logged server-side; the client gets a generic message.
+"""
+import types
+
+import pytest
+import requests
+
+import backend.file_routes as file_routes
+
+
+def failing_paperless(monkeypatch):
+ """A Paperless handler whose requests fail with a URL-bearing error."""
+ def _boom(*args, **kwargs):
+ raise requests.exceptions.ConnectionError(
+ "HTTPConnectionPool(host='internal.paperless.local', port=8000): "
+ "Max retries exceeded with url: /api/documents/?query=secret"
+ )
+
+ handler = types.SimpleNamespace(base_url="http://internal.paperless.local:8000", get=_boom)
+ monkeypatch.setattr(
+ file_routes, "get_paperless_handler", lambda conn: handler)
+ return handler
+
+
+def _assert_no_internal_detail(response):
+ body = response.get_data(as_text=True)
+ for leaked in ("internal.paperless.local", "8000", "api/documents", "HTTPConnectionPool"):
+ assert leaked not in body, body
+
+
+def test_paperless_search_failure_hides_internal_detail(
+ client, user_factory, failing_paperless):
+ user = user_factory()
+ r = client.get("/api/paperless/search?query=secret", headers=user["headers"])
+ assert r.status_code == 400
+ _assert_no_internal_detail(r)
+ assert "Paperless-ngx search failed" in r.get_json()["message"]
+
+
+def test_paperless_tags_failure_hides_internal_detail(
+ client, user_factory, failing_paperless):
+ user = user_factory()
+ r = client.get("/api/paperless/tags", headers=user["headers"])
+ assert r.status_code == 400
+ _assert_no_internal_detail(r)
+ assert "Paperless-ngx tags failed" in r.get_json()["message"]
+
+
+def test_paperless_auth_failure_keeps_friendly_message(
+ client, user_factory, monkeypatch):
+ """A 401/403 from Paperless still tells the user it is credentials."""
+ def _denied(*args, **kwargs):
+ response = requests.Response()
+ response.status_code = 403
+ error = requests.exceptions.HTTPError("403 Forbidden")
+ error.response = response
+ raise error
+
+ handler = types.SimpleNamespace(base_url="http://internal:8000", get=_denied)
+ monkeypatch.setattr(
+ file_routes, "get_paperless_handler", lambda conn: handler)
+ user = user_factory()
+ r = client.get("/api/paperless/search", headers=user["headers"])
+ assert r.status_code == 400
+ assert "rejected the credentials" in r.get_json()["message"]
+ assert "internal" not in r.get_data(as_text=True)