简体   繁体   English

安全地为多租户数据库创建新模式

[英]Safely create new schemas for multi-tenant database

So I'm creating a multi-tenant database, where each tenant will have their own schema. 所以我正在创建一个多租户数据库,每个租户都有自己的架构。 I'm using Java JDBC & MySQL. 我正在使用Java JDBC和MySQL。 When a new tenant signs up, the name they assign for their group becomes the schema name. 当新租户注册时,他们为其组分配的名称将成为架构名称。

My challenge is how to do this without having SQL injection. 我的挑战是如何在不注入SQL的情况下执行此操作。 Apparently you can't parameterize create schema statements, like this: 显然你无法参数化创建模式语句,如下所示:

create schema ?

If I allow the name in the string to just be placed at the end of that statement, I open a ginormous security hole for SQL injection. 如果我允许将字符串中的名称放在该语句的末尾,我会为SQL注入打开一个巨大的安全漏洞。 So I'm just wondering what the best approach is here. 所以我只是想知道这里最好的方法是什么。

My best guess is to have the schema names not actually be the group names, but create them through an internal process. 我最好的猜测是让模式名称实际上不是组名,而是通过内部进程创建它们。 Something along the lines of (groupId + firstThreeLettersOfName). 类似于(groupId + firstThreeLettersOfName)的东西。 But I'm open to ideas. 但我对创意持开放态度。

Thanks. 谢谢。

First, use a cleanup procedure. 首先,使用清理程序。 Strip all chars except for alphanumeric and underscore, and limit the lenght. 剥除除字母数字和下划线之外的所有字符,并限制长度。

Second, wrap the name in backward apostrophes. 其次,将名称包含在后向撇号中。 That should give you the desired result. 这应该会给你想要的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用PostgreSQL中的Schema的Hibernate和多租户数据库 - Hibernate and Multi-Tenant Database using Schemas in PostgreSQL 具有共享数据库和鉴别器列的多租户 - Multi-Tenant with shared database and discriminator column 每个租户多租户连接提供程序的Hibernate数据库正在为单个租户创建多个数据库连接 - Hibernate database per tenant multi-tenant connection provider is creating multiple database connections for single tenant 如何实现“共享数据库,独立模式”的多租户策略 - How to implement the “Shared database, separate schema” multi-tenant strategy 多租户环境中的Spring Boot + Thymeleaf + Database TemplateResolver - Spring Boot + Thymeleaf + Database TemplateResolver in a Multi-Tenant environment 具有Spring Boot和Hibernate的多租户和中央数据库 - Multi-Tenant and Central Database with Spring Boot and Hibernate 带有 KeyCloak 的多租户 Quarkus? - Multi-tenant Quarkus with KeyCloak? 带有eclipse链接的多租户 - multi-tenant with eclipse link Quarkus 多租户应用 - Quarkus Multi-tenant Application 如何在多租户(每租户数据库)感知 Spring 引导应用程序中使用固定数据库 - How do you use a fixed database in a multi-tenant (database-per-tenant) aware Spring Boot application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM