-
Notifications
You must be signed in to change notification settings - Fork 3
Demo Base Kit #252
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
base: main
Are you sure you want to change the base?
Demo Base Kit #252
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨ PR Review
The PR introduces a comprehensive base kit with database integration, order history functionality, and improved UI. The implementation includes several concerning security and concurrency issues that need attention.
3 issues detected:
🐞 Bug - Concurrent access to the same file without synchronization can lead to data corruption or loss
Details: The file-based billing queue implementation has a race condition where concurrent requests for the same user could corrupt the JSON file or lose data during read-modify-write operations.
File:services/billing-csharp/Controllers/BillingController.cs (56-72)
🔒 Security - String manipulation on untrusted input from external service creates potential injection vulnerability
Details: The token validation logic uses string manipulation with split() and contains() methods that could be vulnerable to injection attacks if the auth service response is compromised or malformed.
File:services/orders-java/src/main/java/com/example/orders/controller/OrderController.java (127-127)
🔒 Security - Global token variable makes it accessible to any script running on the page
Details: The authentication token is stored in a global variable which could be accessed by malicious scripts or browser extensions, potentially leading to session hijacking.
File:frontend/public/app.js (14-14)
Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using. We'd love your feedback! 🚀
private async Task QueueForBillingSystemAsync(string username, object payload) | ||
{ | ||
Directory.CreateDirectory(StorageDirectory); | ||
var filePath = Path.Combine(StorageDirectory, $"{username}.json"); | ||
List<object> payloads = new(); | ||
|
||
if (System.IO.File.Exists(filePath)) | ||
{ | ||
try | ||
{ | ||
payloads = JsonSerializer.Deserialize<List<object>>(await System.IO.File.ReadAllTextAsync(filePath)) ?? new(); | ||
} | ||
catch { } | ||
} | ||
|
||
payloads.Add(payload); | ||
await System.IO.File.WriteAllTextAsync(filePath, JsonSerializer.Serialize(payloads, new JsonSerializerOptions { WriteIndented = true })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐞 Bug - Race Condition: Add file locking mechanism using FileStream with exclusive access or implement proper synchronization using locks around the file operations.
private async Task QueueForBillingSystemAsync(string username, object payload) | |
{ | |
Directory.CreateDirectory(StorageDirectory); | |
var filePath = Path.Combine(StorageDirectory, $"{username}.json"); | |
List<object> payloads = new(); | |
if (System.IO.File.Exists(filePath)) | |
{ | |
try | |
{ | |
payloads = JsonSerializer.Deserialize<List<object>>(await System.IO.File.ReadAllTextAsync(filePath)) ?? new(); | |
} | |
catch { } | |
} | |
payloads.Add(payload); | |
await System.IO.File.WriteAllTextAsync(filePath, JsonSerializer.Serialize(payloads, new JsonSerializerOptions { WriteIndented = true })); | |
private readonly object _fileLock = new object(); | |
private async Task QueueForBillingSystemAsync(string username, object payload) | |
{ | |
Directory.CreateDirectory(StorageDirectory); | |
var filePath = Path.Combine(StorageDirectory, $"{username}.json"); | |
await Task.Run(() => | |
{ | |
lock (_fileLock) | |
{ | |
List<object> payloads = new(); | |
if (System.IO.File.Exists(filePath)) | |
{ | |
try | |
{ | |
payloads = JsonSerializer.Deserialize<List<object>>(System.IO.File.ReadAllText(filePath)) ?? new(); | |
} | |
catch { } | |
} | |
payloads.Add(payload); | |
System.IO.File.WriteAllText(filePath, JsonSerializer.Serialize(payloads, new JsonSerializerOptions { WriteIndented = true })); | |
} | |
}); |
@@ -49,6 +126,7 @@ protected String validateToken(String token) { | |||
String body = authResponse.getBody(); | |||
return body.contains("username") ? body.split(":")[1].replaceAll("[\"{} ]", "") : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security - SQL Injection: Use proper JSON parsing library to parse the auth service response instead of string manipulation methods. Validate the response structure before extracting the username.
return body.contains("username") ? body.split(":")[1].replaceAll("[\"{} ]", "") : null; | |
try { | |
org.json.JSONObject jsonResponse = new org.json.JSONObject(body); | |
return jsonResponse.has("username") ? jsonResponse.getString("username") : null; | |
} catch (org.json.JSONException e) { | |
e.printStackTrace(); | |
return null; | |
} |
const data = await res.json(); | ||
token = data.token; | ||
if (!res.ok) return document.getElementById("output").textContent = "Login failed."; | ||
token = (await res.json()).token; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security - Token Exposure: Store the token in a more secure location such as sessionStorage or implement proper token management with secure storage practices.
token = (await res.json()).token; | |
sessionStorage.setItem('authToken', (await res.json()).token); |
✨ PR Description
Purpose: Adds order history functionality and Swagger documentation to the frontend gateway and improves backend data persistence.
Main changes:
/api/orders/history
endpoint with frontend UI integration for viewing past ordersGenerated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using. We'd love your feedback! 🚀