POST /api/collections returns 500 instead of 400 for ADM validation failures

未关闭 适合新手
#505 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
86/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
javascript
领域
api, backend

调研方向

从 collections-controller.js:create() 入手,以 POST /api/collections 的复现作为入口,检查 BaseService.create() 的校验错误是如何被处理的。保留结构化的 400 校验详情,并验证不受支持的 x_mitre_domains 和空的 x_mitre_contents 会在不持久化的情况下返回 400。

由索引模型根据 Issue 内容生成。

描述

Description

Invalid collection payloads return a generic HTTP 500 instead of a validation response identifying the rejected fields.

Observed on REST API 4.24.0, commit 69b37fe769e6abe7675d413451a8361aecc36bea.

Reproduction
  1. Prepare a valid x-mitre-collection payload containing at least one existing object revision in x_mitre_contents.
  2. Add "x_mitre_domains": ["enterprise-attack"] to its stix object.
  3. POST the payload to /api/collections.

Actual: HTTP 500:

Unable to create collection. Server error.

Expected: HTTP 400 with structured ADM validation details indicating that x_mitre_domains is an unrecognized collection field.

Removing x_mitre_domains allows the nonempty collection to return 201 and persist successfully. Explicitly empty x_mitre_contents also produces the same misleading 500.

Cause and suggested fix

BaseService.create() throws ValidationError, but collections-controller.js:create() maps every exception except DuplicateIdError to a generic 500. The log contains:

Failed with error: ValidationError: ADM validation failed

Preserve the normal validation-error handling and field-level details. Add regressions asserting 400 and no persistence for unsupported fields and empty contents.

These requests did not crash the REST process; REST and MongoDB remained healthy during verification.

主要语言
JavaScript
星标
56
派生
18
平均合并
19 小时 39 分钟
30 天内合并 PR
7

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

mitre-attack/attack-workbench-rest-api 的其他 Issue

查看 mitre-attack/attack-workbench-rest-api 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。