-
Notifications
You must be signed in to change notification settings - Fork 115
DEVOPS-11038: Пакетная отправка сообщений PinkRabbitMQ #106
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: master
Are you sure you want to change the base?
Conversation
🔍 Code ReviewHello ipalenov (@ipalenov)! Thank you for introducing batch message sending to PinkRabbitMQ. This is a valuable feature that promises significant performance improvements. Overall, the change to enable batch publishing is a positive step towards optimizing message throughput. However, several critical areas related to input validation, error handling, and test coverage need attention to ensure the stability, security, and robustness of this new functionality. 🎯 Key Changes & Highlights✨ **Batch Publishing Feature**The introduction of 🚨 Issues & Suggestions🔐 DoS via Unvalidated JSON InputMalformed or oversized JSON input can lead to resource exhaustion and Denial of Service.Problem: The Fix: Implement robust input validation and error handling. Before calling // Example for batchPublishImpl
try {
const std::string& jsonInput = ctx.stringParamUtf8();
if (jsonInput.length() > MAX_BATCH_JSON_SIZE) { // Define MAX_BATCH_JSON_SIZE
ctx.setError(u16Converter.from_bytes("Batch messages JSON input too large."));
return false;
}
auto messages = json::parse(jsonInput);
// ... rest of the logic ...
} catch (const json::parse_error& e) {
ctx.setError(u16Converter.from_bytes("JSON parsing error for messages: " + std::string(e.what())));
return false;
}
// Example for headersFromJson
AMQP::Table RabbitMQClient::headersFromJson(const std::string& propsJson, bool forConsume)
{
if (propsJson.empty()) {
return AMQP::Table();
}
if (propsJson.length() > MAX_HEADERS_JSON_SIZE) { // Define MAX_HEADERS_JSON_SIZE
// Handle error appropriately, e.g., log and return empty table or throw
return AMQP::Table();
}
try {
auto object = json::parse(propsJson);
return headersFromJson(object, forConsume);
} catch (const json::parse_error& e) {
// Log error and potentially return an empty/invalid table
return AMQP::Table();
}
}🏗️ Unsafe Batch Message AccessDirect access to JSON fields in batch messages can cause crashes if keys are missing.Problem: In Fix: Before accessing for (auto& it : messages) {
if (!it.contains("routingKey") || !it.contains("body")) {
ctx.setError(u16Converter.from_bytes("Batch message missing 'routingKey' or 'body'. Skipping message."));
// Log the error with more context if possible
continue; // Skip this malformed message and process others
}
std::string routingKey = it["routingKey"];
std::string message = it["body"];
// ... rest of the logic ...
}✨ Incomplete Test CoverageNew batch publish functionality lacks comprehensive test coverage for edge cases.Problem: The Fix: Expand the test suite in
🔐 Validate Routing KeyAdd validation for routingKey format to prevent downstream issues.Why: The How: Implement a std::string routingKey = it["routingKey"];
if (!isValidRoutingKey(routingKey)) { // Implement isValidRoutingKey based on project standards
ctx.setError(u16Converter.from_bytes("Invalid routing key format."));
return false;
}⚡ Use
|
No description provided.