Spaces:
Sleeping
Sleeping
Update app.js
Browse files
app.js
CHANGED
|
@@ -159,7 +159,6 @@ async function generateUniquePin() {
|
|
| 159 |
return pin;
|
| 160 |
}
|
| 161 |
|
| 162 |
-
/*
|
| 163 |
// ============================================================================
|
| 164 |
// PUBLIC ROUTE: LEGACY DIRECT REGISTRATION
|
| 165 |
// ============================================================================
|
|
@@ -185,8 +184,6 @@ app.post('/register-handle', async (req, res) => {
|
|
| 185 |
return res.status(500).json({ error: "Failed to map permanent handle." });
|
| 186 |
}
|
| 187 |
});
|
| 188 |
-
*/
|
| 189 |
-
|
| 190 |
|
| 191 |
// ============================================================================
|
| 192 |
// ANP HANDSHAKE ROUTE (Protocol Registration, Room Creation & Joining)
|
|
@@ -243,6 +240,11 @@ app.post('/handshake', async (req, res) => {
|
|
| 243 |
|
| 244 |
if (handleErr || !persistentHost) return res.status(404).json({ type: 'CANCEL', reason: `Handle '${handle}' offline or does not exist.` });
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
const pin = await generateUniquePin();
|
| 247 |
|
| 248 |
const { data: room, error: roomErr } = await supabase.from('ginger_rooms').insert({
|
|
@@ -290,6 +292,11 @@ app.post('/handshake', async (req, res) => {
|
|
| 290 |
|
| 291 |
if (error || !room) return res.status(404).json({ type: 'CANCEL', reason: "Active pairing room not found." });
|
| 292 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
await supabase.from('ginger_rooms').update({
|
| 294 |
receiver_session_id: session_id,
|
| 295 |
receiver_pub_key: buyer_pub_key,
|
|
|
|
| 159 |
return pin;
|
| 160 |
}
|
| 161 |
|
|
|
|
| 162 |
// ============================================================================
|
| 163 |
// PUBLIC ROUTE: LEGACY DIRECT REGISTRATION
|
| 164 |
// ============================================================================
|
|
|
|
| 184 |
return res.status(500).json({ error: "Failed to map permanent handle." });
|
| 185 |
}
|
| 186 |
});
|
|
|
|
|
|
|
| 187 |
|
| 188 |
// ============================================================================
|
| 189 |
// ANP HANDSHAKE ROUTE (Protocol Registration, Room Creation & Joining)
|
|
|
|
| 240 |
|
| 241 |
if (handleErr || !persistentHost) return res.status(404).json({ type: 'CANCEL', reason: `Handle '${handle}' offline or does not exist.` });
|
| 242 |
|
| 243 |
+
// 🛡️ ANTI-LOOP SHIELD: Prevent an agent from initiating a connection to itself
|
| 244 |
+
if (persistentHost.pub_key === buyer_pub_key) {
|
| 245 |
+
return res.json({ type: 'CANCEL', reason: "Cannot establish a P2P session with your own handle." });
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
const pin = await generateUniquePin();
|
| 249 |
|
| 250 |
const { data: room, error: roomErr } = await supabase.from('ginger_rooms').insert({
|
|
|
|
| 292 |
|
| 293 |
if (error || !room) return res.status(404).json({ type: 'CANCEL', reason: "Active pairing room not found." });
|
| 294 |
|
| 295 |
+
// 🛡️ ANTI-LOOP SHIELD: Prevent an agent from joining its own room
|
| 296 |
+
if (room.initiator_pub_key === buyer_pub_key) {
|
| 297 |
+
return res.json({ type: 'CANCEL', reason: "Cannot join your own temporary P2P room." });
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
await supabase.from('ginger_rooms').update({
|
| 301 |
receiver_session_id: session_id,
|
| 302 |
receiver_pub_key: buyer_pub_key,
|