Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tenant ID overriden when saving without notice #329

Open
krystof-k opened this issue Dec 31, 2023 · 1 comment
Open

Tenant ID overriden when saving without notice #329

krystof-k opened this issue Dec 31, 2023 · 1 comment

Comments

@krystof-k
Copy link

krystof-k commented Dec 31, 2023

I'm not sure whether this is a target behavior but when saving new object, the tenant ID is simply overriden with the current tenant although I'd expect it to fail:

irb(main):020:0> ActsAsTenant.current_tenant = Account.find_by(name: 'first')
irb(main):021:0> file = MyFile.new(account_id: Account.find_by(name: 'second').id)
=> #<MyFile:0x0000ffff9e54d618 account_id: "43493dde-c683-4ffd-a40d-de8801d71648", created_at: nil>
irb(main):022:0> file.save
  TRANSACTION (0.8ms)  BEGIN
  RawFile Create (1.3ms)  INSERT INTO "my_files" ("account_id", "created_at") VALUES ($1, $2, $3) RETURNING "id"  
  [["account_id", "a5106c5b-caf7-442b-ad1c-3e1fec36fc39"], 
  ["created_at", "2023-12-31 18:14:16.513713"]]
  TRANSACTION (1.1ms)  COMMIT                                                      
=> true 

Notice the UUID submitted is overriden by the tenant UUID in the SQL query.

@simkim
Copy link

simkim commented Nov 22, 2024

Same if you build with relations
ActsAsTenant.current_tenant = Account.find_by(name: 'first')
Account.find_by(name: 'second').files.build

this will override the account id and build the file on the first account which is dangerous.

It should raise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants