-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add p2p test result dashboard #12
Conversation
Changed arrow direction from -> to <- and swapped node positions to show target <- source instead of source -> target
app.get('/events', async (req, res) => { | ||
res.setHeader('Content-Type', 'text/event-stream'); | ||
res.setHeader('Cache-Control', 'no-cache'); | ||
res.setHeader('Connection', 'keep-alive'); | ||
|
||
try { | ||
const result = await appPool.query('SELECT data FROM test_runs'); | ||
const initialData = result.rows.map(row => row.data); | ||
res.write(`data: ${JSON.stringify({ type: 'initial', data: initialData })}\n\n`); | ||
} catch (error) { | ||
console.error('Error fetching initial data:', error); | ||
} | ||
|
||
clients.add(res); | ||
req.on('close', () => clients.delete(res)); | ||
}); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
a database access
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 2 months ago
To fix the problem, we need to introduce rate limiting to the /events
endpoint to prevent abuse and potential denial-of-service attacks. The best way to achieve this is by using the express-rate-limit
middleware, which allows us to set a maximum number of requests that a client can make within a specified time window.
- Install the
express-rate-limit
package. - Import the
express-rate-limit
package in thedashboard/src/server/index.js
file. - Create a rate limiter with appropriate settings (e.g., maximum of 100 requests per 15 minutes).
- Apply the rate limiter to the
/events
endpoint.
-
Copy modified line R6 -
Copy modified lines R78-R83 -
Copy modified line R100
@@ -5,2 +5,3 @@ | ||
import dotenv from 'dotenv'; | ||
import rateLimit from 'express-rate-limit'; | ||
|
||
@@ -76,2 +77,8 @@ | ||
|
||
// Set up rate limiter: maximum of 100 requests per 15 minutes | ||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // max 100 requests per windowMs | ||
}); | ||
|
||
const clients = new Set(); | ||
@@ -92,3 +99,3 @@ | ||
// Modified SSE endpoint | ||
app.get('/events', async (req, res) => { | ||
app.get('/events', limiter, async (req, res) => { | ||
res.setHeader('Content-Type', 'text/event-stream'); |
-
Copy modified lines R20-R21
@@ -19,3 +19,4 @@ | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1" | ||
"react-dom": "^18.3.1", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
app.get('*', (req, res) => { | ||
res.sendFile(join(__dirname, '../../dist/index.html')); | ||
}); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
a file system access
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 2 months ago
To fix the problem, we need to introduce rate limiting to the Express application. The best way to do this is by using the express-rate-limit
package, which allows us to set a maximum number of requests that can be made to the server within a specified time window. This will help prevent abuse and mitigate the risk of denial-of-service attacks.
We will:
- Install the
express-rate-limit
package. - Import the package in the
dashboard/src/server/index.js
file. - Set up a rate limiter with appropriate configuration.
- Apply the rate limiter to the specific route handler that performs the file system access.
-
Copy modified line R6 -
Copy modified lines R76-R82 -
Copy modified line R119
@@ -5,2 +5,3 @@ | ||
import dotenv from 'dotenv'; | ||
import rateLimit from 'express-rate-limit'; | ||
|
||
@@ -74,2 +75,9 @@ | ||
const app = express(); | ||
|
||
// Set up rate limiter: maximum of 100 requests per 15 minutes | ||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // max 100 requests per windowMs | ||
}); | ||
|
||
const PORT = 3322; | ||
@@ -110,3 +118,3 @@ | ||
// Serve index.html for all routes | ||
app.get('*', (req, res) => { | ||
app.get('*', limiter, (req, res) => { | ||
res.sendFile(join(__dirname, '../../dist/index.html')); |
-
Copy modified lines R20-R21
@@ -19,3 +19,4 @@ | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1" | ||
"react-dom": "^18.3.1", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
app.post('/update', async (req, res) => { | ||
const update = req.body; | ||
|
||
try { | ||
if (update.type === 'newTest' || update.type === 'updateTest') { | ||
await appPool.query( | ||
'INSERT INTO test_runs (id, data) VALUES ($1, $2) ON CONFLICT (id) DO UPDATE SET data = $2', | ||
[update.data.id, update.data] | ||
); | ||
} | ||
|
||
broadcastUpdate(update); | ||
res.sendStatus(200); | ||
} catch (error) { | ||
console.error('Error updating data:', error); | ||
res.sendStatus(500); | ||
} | ||
}); |
Check failure
Code scanning / CodeQL
Missing rate limiting High
a database access
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 2 months ago
To fix the problem, we will introduce rate limiting to the Express application using the express-rate-limit
package. This package allows us to set a maximum number of requests that can be made to the server within a specified time window. We will apply this rate limiting middleware to the /update
endpoint to prevent abuse.
- Install the
express-rate-limit
package. - Import the
express-rate-limit
package in thedashboard/src/server/index.js
file. - Configure the rate limiter with appropriate settings (e.g., maximum number of requests and time window).
- Apply the rate limiter middleware to the
/update
endpoint.
-
Copy modified line R6 -
Copy modified lines R76-R79 -
Copy modified line R127
@@ -5,2 +5,3 @@ | ||
import dotenv from 'dotenv'; | ||
import rateLimit from 'express-rate-limit'; | ||
|
||
@@ -74,2 +75,6 @@ | ||
const app = express(); | ||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // limit each IP to 100 requests per windowMs | ||
}); | ||
const PORT = 3322; | ||
@@ -121,3 +126,3 @@ | ||
// Modified update endpoint | ||
app.post('/update', async (req, res) => { | ||
app.post('/update', limiter, async (req, res) => { | ||
const update = req.body; |
-
Copy modified lines R20-R21
@@ -19,3 +19,4 @@ | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1" | ||
"react-dom": "^18.3.1", | ||
"express-rate-limit": "^7.4.1" | ||
}, |
Package | Version | Security advisories |
express-rate-limit (npm) | 7.4.1 | None |
No description provided.