如何正确使用UUID作为@PathVariable来隐藏敏感数据?带 Spring Boot 的 REST API

问题描述 投票:0回答:1

我有这个基本的删除请求:

@DeleteMapping("/{id}")
public ResponseEntity<String> deleteSubscription(@PathVariable Long id) {
    subscriptionService.deleteSubscription(id);

    return ResponseEntity.noContent().build();
}

所以我被告知这是不行的,因为敏感数据(id)会被暴露,更好的方法是使用 UUID,但该怎么做?

我正在使用 Spring Data JPA、MariaDB。

我不知道该怎么做。 UUID 必须是主键才能替换 id 或某种生成和验证的值?

java spring mariadb spring-restcontroller
1个回答
0
投票

安全

出于安全原因是否应使用 uuid 或序列号取决于要求 - 只有您知道。任何答案都将基于意见。

还要考虑 MariaDB 使用 UUID 类型 1(基于时间戳),可以提取时间戳。

技术方面

序列号(自动增量)应始终优先于 UUID:

  • uuid 为 16 个字节(相比之下,使用序列号需要 4 或 8 个字节)
  • 无法自然排序
  • 玛丽亚数据库< 10.7 doesn't have UUID data type, so you need to unhex it before you can store it as 16 bytes instead of a 36 byte char.
  • 索引更加复杂且速度更慢(请参阅此处
  • 基于语句的复制不适用于 UUID()。
© www.soinside.com 2019 - 2024. All rights reserved.