Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Demo Base Kit #252

wants to merge 1 commit into from

Conversation

vlussenburg
Copy link
Collaborator

@vlussenburg vlussenburg commented Jun 28, 2025

✨ PR Description

Purpose: Adds order history functionality and Swagger documentation to the frontend gateway and improves backend data persistence.

Main changes:

  • Added /api/orders/history endpoint with frontend UI integration for viewing past orders
  • Implemented order storage in H2 database within OrderController for persistent order history
  • Added Swagger documentation with swagger-jsdoc and swagger-ui-express for API documentation

Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using. We'd love your feedback! 🚀

Copy link

@gitstream-cm gitstream-cm bot left a 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! 🚀

Comment on lines +56 to +72
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 }));
Copy link

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.

Suggested change
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;
Copy link

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.

Suggested change
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;
Copy link

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.

Suggested change
token = (await res.json()).token;
sessionStorage.setItem('authToken', (await res.json()).token);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant