Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/security-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ jobs:
uses: actions/checkout@v4

- name: Run Rust Security Audit Check
uses: rustsec/audit-check-action@v2.0.0
uses: taiki-e/install-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
working-directory: ./contracts/soroban
tool: cargo-audit

- name: Audit Rust dependencies
working-directory: ./contracts/soroban
run: cargo audit
1 change: 1 addition & 0 deletions backend/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
testEnvironment: 'node',
setupFiles: ['<rootDir>/tests/setup.js'],
coverageDirectory: 'coverage',
collectCoverageFrom: [
'**/*.js',
Expand Down
23 changes: 23 additions & 0 deletions backend/middleware/geoBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const blockedCountries = () => new Set(
String(process.env.BLOCKED_COUNTRIES || '')
.split(',').map((country) => country.trim().toUpperCase()).filter(Boolean),
);

function clientIp(req) {
const forwarded = req.headers['x-forwarded-for'];
return String(forwarded || req.headers['cf-connecting-ip'] || req.ip || '').split(',')[0].trim();
}

function geoBlock(req, res, next) {
const country = String(
req.headers['cf-ipcountry'] || req.headers['x-vercel-ip-country'] || req.headers['x-country-code'] || '',
).toUpperCase();
if (country && blockedCountries().has(country)) {
return res.status(451).json({ error: 'This region is not permitted to access wagered gameplay.' });
}
req.clientIp = clientIp(req);
req.clientCountry = country || null;
return next();
}

module.exports = { geoBlock, clientIp };
39 changes: 39 additions & 0 deletions backend/package-lock.json

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

3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
"@supabase/supabase-js": "^2.95.3",
"axios": "^1.6.0",
"cors": "^2.8.5",
"helmet": "^8.0.0",
"dotenv": "^16.4.5",
"express": "^5.2.1",
"helmet": "^8.0.0",
"jsonwebtoken": "^9.0.3",
"pg": "^8.23.0",
"prom-client": "^15.1.3",
"socket.io": "^4.8.3",
"stellar-sdk": "^13.3.0"
},
Expand Down
4 changes: 3 additions & 1 deletion backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const cronService = require("./services/cronService");
const supabase = require("./config/supabase");
const logger = require("./utils/logger");
const { errorHandler, installGlobalHandlers } = require("./middleware/errorHandler");
const { geoBlock } = require("./middleware/geoBlock");
const { createRateLimiter } = require("./middleware/rateLimiter");
const { sanitizeInput } = require("./middleware/sanitizeInput");

Expand Down Expand Up @@ -67,6 +68,7 @@ app.use(
}),
);
app.use(express.json());
app.use(geoBlock);
app.use(createRateLimiter({ windowMs: 60_000, max: 100 }));
app.use(sanitizeInput);

Expand Down Expand Up @@ -215,4 +217,4 @@ cronService.start();

server.listen(PORT, "0.0.0.0", () => {
console.log(`Chesster backend running on port ${PORT}`);
});
});
4 changes: 4 additions & 0 deletions backend/tests/escrowService.horizon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
* Tests for Stellar Horizon Transaction Indexer
*/

jest.mock("@stellar/stellar-sdk", () => ({
Networks: { TESTNET: "Test SDF Network ; September 2015" },
}));

const escrowService = require("../services/escrowService");

jest.mock("axios");
Expand Down
13 changes: 13 additions & 0 deletions backend/tests/healthRoutes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@

const request = require("supertest");
const express = require("express");

// Keep route tests independent of the SDK's ESM-only transitive hash module.
jest.mock("@stellar/stellar-sdk", () => ({
Networks: { TESTNET: "Test SDF Network ; September 2015" },
rpc: { Server: jest.fn(() => ({ getLatestLedger: jest.fn().mockResolvedValue({ sequence: 1 }) })) },
}));

const healthRoutes = require("../routes/healthRoutes");

describe("Health Check Routes", () => {
let app;

beforeEach(() => {
// Other suites exercise missing configuration and may mutate process.env.
// Restore the route test's safe configuration for every test in this file.
process.env.SUPABASE_URL = "http://localhost";
process.env.SUPABASE_ANON_KEY = "test-anon-key";
process.env.SUPABASE_KEY = "test-service-key";
process.env.SOROBAN_RPC_URL = "http://localhost";
app = express();
app.use(express.json());
app.use("/api", healthRoutes);
Expand Down
5 changes: 5 additions & 0 deletions backend/tests/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Keep tests hermetic: production configuration remains fail-closed, while
// modules imported by isolated route/service tests get safe placeholders.
process.env.SUPABASE_URL ||= 'http://localhost';
process.env.SUPABASE_ANON_KEY ||= 'test-anon-key';
process.env.SUPABASE_KEY ||= 'test-service-key';
Loading