Skip to content

Commit 0fcd0b3

Browse files
committed
Fix reporteds security issues
1 parent ae52b22 commit 0fcd0b3

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

.github/workflows/security-scan.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,13 @@ jobs:
6060

6161
- name: Perform CodeQL Analysis
6262
uses: github/codeql-action/analyze@v3
63+
with:
64+
upload: false
65+
66+
- name: Upload CodeQL SARIF
67+
if: always()
68+
uses: github/codeql-action/upload-sarif@v3
69+
with:
70+
sarif_file: 'results'
71+
wait-for-processing: true
72+
category: 'CodeQL'

kcn_proxy/web/api.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ async def get_vardiff_state():
476476
try:
477477
return JSONResponse({"enabled": True, **manager.export_state()})
478478
except Exception as e:
479-
return JSONResponse({"enabled": True, "error": str(e)}, status_code=500)
479+
logger.error("Error exporting vardiff state: %s", e, exc_info=True)
480+
return JSONResponse({"enabled": True, "error": "Failed to retrieve state"}, status_code=500)
480481

481482

482483
@app.get("/favicon.ico")
@@ -534,8 +535,8 @@ async def clear_best_shares():
534535
}
535536
)
536537
except Exception as e:
537-
logger.error(f"Error clearing best shares: {e}")
538-
return JSONResponse({"status": "error", "message": str(e)}, status_code=500)
538+
logger.error("Error clearing best shares: %s", e)
539+
return JSONResponse({"status": "error", "message": "Failed to clear shares"}, status_code=500)
539540

540541

541542
@app.get("/api/lcn_hash_fix_status")
@@ -576,7 +577,8 @@ async def lcn_hash_fix_status():
576577
{"error": "Database not enabled", "show_button": False}, status_code=503
577578
)
578579
except Exception as e:
579-
return JSONResponse({"error": str(e), "show_button": False}, status_code=500)
580+
logger.error("Error checking LCN hash fix status: %s", e, exc_info=True)
581+
return JSONResponse({"error": "Internal error", "show_button": False}, status_code=500)
580582

581583

582584
@app.post("/api/fix_lcn_aux_hashes")
@@ -651,7 +653,8 @@ def _rpc(method: str, params: list):
651653
try:
652654
rpc_hash = _rpc("getblockhash", [height]).lower()
653655
except Exception as e:
654-
diffs.append((height, stored, f"RPC_ERROR:{e}"))
656+
logger.debug("RPC error checking block %d: %s", height, e)
657+
diffs.append((height, stored, f"RPC_ERROR"))
655658
continue
656659
if stored != rpc_hash:
657660
diffs.append((height, stored, rpc_hash))
@@ -731,7 +734,8 @@ async def get_share_stats(worker: str = None, minutes: int = 10):
731734
except ImportError:
732735
return JSONResponse({"error": "Database not enabled"}, status_code=503)
733736
except Exception as e:
734-
return JSONResponse({"error": str(e)}, status_code=500)
737+
logger.error("Error retrieving share stats: %s", e)
738+
return JSONResponse({"error": "Failed to retrieve share statistics"}, status_code=500)
735739

736740

737741
@app.post("/api/cleanup")
@@ -748,7 +752,8 @@ async def manual_cleanup():
748752
except ImportError:
749753
return JSONResponse({"error": "Database not enabled"}, status_code=503)
750754
except Exception as e:
751-
return JSONResponse({"error": str(e)}, status_code=500)
755+
logger.error("Error during cleanup: %s", e)
756+
return JSONResponse({"error": "Failed to complete cleanup"}, status_code=500)
752757

753758

754759
@app.get("/api/health")
@@ -1013,8 +1018,8 @@ async def clear_miner_record(worker_name: str):
10131018
await delete_miner_session(worker_name)
10141019
return JSONResponse({"status": "success", "worker_name": worker_name})
10151020
except Exception as e:
1016-
logger.error(f"Error deleting miner record {worker_name}: {e}")
1017-
return JSONResponse({"status": "error", "message": str(e)}, status_code=500)
1021+
logger.error("Error deleting miner record %s: %s", worker_name, e)
1022+
return JSONResponse({"status": "error", "message": "Failed to delete record"}, status_code=500)
10181023

10191024

10201025
@app.get("/api/earnings")
@@ -1151,8 +1156,8 @@ async def get_earnings_estimate():
11511156
return JSONResponse(earnings)
11521157

11531158
except Exception as e:
1154-
logger.error(f"Error calculating earnings: {e}", exc_info=True)
1159+
logger.error("Error calculating earnings: %s", e, exc_info=True)
11551160
return JSONResponse(
1156-
{"status": "error", "message": str(e)},
1161+
{"status": "error", "message": "Failed to calculate earnings"},
11571162
status_code=500,
11581163
)

0 commit comments

Comments
 (0)