Aias00 opened a new issue, #6446:
URL: https://github.com/apache/shenyu/issues/6446

   ### Current Behavior
   
   `EmailAlertNotifyStrategy.buildAlertHtmlTemplate()` dereferences `alert` 
before checking whether it is null, and formats `dateCreated` without guarding 
against a null date.
   
   Evidence:
   
   
`shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/EmailAlertNotifyStrategy.java:75-87`
   
   ```java
   context.setVariable("content", alert.getContent());
   SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd 
HH:mm:ss");
   Date alertTime = alert.getDateCreated();
   if (Objects.isNull(alert)) {
       alertTime = new Date();
   }
   String alarmTime = simpleDateFormat.format(alertTime);
   ```
   
   `AlertReportController` accepts the request body and dispatches it directly:
   
   
`shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/AlertReportController.java:47-48`
   
   ```java
   public ShenyuAdminResult reportAlert(@Valid @RequestBody final AlarmContent 
alarmContent) {
       alertDispatchService.dispatchAlert(alarmContent);
   ```
   
   A null/partial `AlarmContent`, or one with missing `dateCreated`, can cause 
a `NullPointerException` in the email alert strategy and make `/alert/report` 
fail with an internal error instead of a controlled validation failure or 
default timestamp.
   
   ### Expected Behavior
   
   Alert reporting should validate missing alert content up front, and the 
email strategy should only dereference `alert` after the null check. Missing 
`dateCreated` should either be rejected as invalid input or default to the 
current time safely.
   
   ### Steps To Reproduce
   
   1. Configure an email alert receiver.
   2. POST `/alert/report` with a body that omits required alert fields or 
omits `dateCreated`.
   3. The email template path dereferences `alert`/`alert.getDateCreated()` 
before validating the values.
   
   ### Suggested Fix
   
   Move the null check before `alert.getContent()` and 
`alert.getDateCreated()`. Add bean validation constraints or explicit 
validation in `AlertReportController`/dispatch service for required 
`AlarmContent` fields.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to