fix(education): fail closed on unsafe question data

This commit is contained in:
2026-07-30 14:30:04 +08:00
parent 4be9c8147e
commit bf24589424
5 changed files with 26 additions and 9 deletions

View File

@@ -397,7 +397,7 @@ public class JavaCatalogProvider implements CatalogProvider, QuestionCatalogProv
@SuppressWarnings({"unchecked", "rawtypes"})
private List<CatalogQuestionDTO.QuestionOptionDTO> parseOptions(String optionsJson) {
if (optionsJson == null || optionsJson.isEmpty()) return Collections.emptyList();
if (optionsJson == null || optionsJson.isBlank()) return Collections.emptyList();
try {
com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
List<java.util.Map> rawList = mapper.readValue(optionsJson, List.class);
@@ -414,7 +414,7 @@ public class JavaCatalogProvider implements CatalogProvider, QuestionCatalogProv
}
return result;
} catch (Exception e) {
return Collections.emptyList();
throw exception(UNSAFE_PROVIDER_PAYLOAD);
}
}

View File

@@ -579,8 +579,11 @@ public class PracticeSessionServiceImpl implements PracticeSessionService {
|| response.getDetails() == null
|| !Objects.equals(existing.getReportId(), response.getReportId())
|| !Objects.equals(existing.getSessionId(), response.getSessionId())) {
log.warn("Invalid submit replay payload: id={}, storedReportId={}, storedSessionId={}, response={}",
existing.getId(), existing.getReportId(), existing.getSessionId(), existing.getResponseJson());
log.warn("Invalid submit replay payload: id={}, storedReportId={}, storedSessionId={}, " +
"responseReportId={}, responseSessionId={}",
existing.getId(), existing.getReportId(), existing.getSessionId(),
response != null ? response.getReportId() : null,
response != null ? response.getSessionId() : null);
throw exception(SUBMIT_IDEMPOTENCY_REPLAY_INVALID);
}
return response;

View File

@@ -33,8 +33,8 @@ public final class QuestionContentSafety {
*/
public static void validateVisibleProviderQuestion(CatalogQuestionDTO question, ErrorCode visibilityError) {
if (question == null || question.getIsPublished() == null || !question.getIsPublished()
|| "hidden".equalsIgnoreCase(question.getStatus())
|| "inactive".equalsIgnoreCase(question.getStatus())) {
|| (question.getStatus() != null && !question.getStatus().isBlank()
&& !"published".equalsIgnoreCase(question.getStatus()))) {
throw exception(visibilityError);
}
}