News for hackers. Stuff that matters.
Re:Salesforce enables ‘modify all’ in user profiles by llamataboot on Friday May 17, 2019 @02:05PM (#19942044)
It's hard to make things totally impossible, but hopefully a good post-mortem will identify the systemic issues that led to it happening, fix them, and not throw anyone under the bus.
Re:Salesforce enables ‘modify all’ in user profiles by londons_explore on Friday May 17, 2019 @03:37PM (#19942809)
"I'll just ask engineering to fix your wonky account"

"Ah yeah - it got in a bad state somehow, let me fix it manually"

    UPDATE permissions SET allow = 1 WHERE user=671156 AND permission=16 AND org=101 OR 102;
Classic SQL blunder...
Re:Salesforce enables ‘modify all’ in user profiles by londons_explore on Friday May 17, 2019 @04:20PM (#19943197)
For anyone reading this who has login access to a production SQL database...:

* Change your account to readonly. Make a new admin account, and put its credentials somewhere hard to get (and audited!).

* Make a directory in git for 'one off sql statements'. Make them all go through code review and have an automated system run them on merge/deploy.

* Enforce style rules with a linter/test, like "UPDATE must have a LIMIT"

* Anything the above process is too burdensome to do should have an API or admin interface built for the purpose.

* Aim to eventually get rid of your readonly account. A leaked customer data dump could kill the company and shouldn't be available to any malware on your machine. You aren't as secure as you think you are.

Re:Salesforce enables ‘modify all’ in user profiles by jjeaff on Friday May 17, 2019 @11:23PM (#19945393)
I agree with everything you said except "a customer database leak could kill a company".

Do we have any example of any company going under due to a data breach? Unfortunately, there seem to be a lot of examples of enormous breaches that did essentially nothing. (like Experian)

Re:Salesforce enables ‘modify all’ in user profiles by londons_explore on Saturday May 18, 2019 @03:25AM (#19946199)
That Italian malware vendor closed down after all it's internal documents were leaked. As did the law firm behind the Panama papers
Re:Salesforce enables ‘modify all’ in user profiles by usmannk on Saturday May 18, 2019 @04:01AM (#19946292)
Hacking Team is still alive and kicking.
Re:Salesforce enables ‘modify all’ in user profiles by jjeaff on Saturday May 18, 2019 @09:06PM (#19950721)
Well yes, but I would attribute the first to simply doing illegal things and getting caught. The data breach just helped them get caught faster. The second, yes, although privacy was literally their number one product and I wouldn't categorize a leak quite the same as a breach.
Re:Salesforce enables ‘modify all’ in user profiles by isatty on Saturday May 18, 2019 @06:14AM (#19946638)
You forgot one thing, if you’re ever executing one off statements make sure they’re in a transaction if it’s an insert or update.

BEGIN; Statement COMMIT; or ROLLBACK

etc

Re:Salesforce enables ‘modify all’ in user profiles by megous on Friday May 17, 2019 @08:36PM (#19944860)
You can also do changes in the transaction and check that it did what you expected before committing.
Re:Salesforce enables ‘modify all’ in user profiles by SOLAR_FIELDS on Saturday May 18, 2019 @08:05AM (#19946946)
Fair warning about this: if your transaction isolation level in your database is set to serialized hanging out in mid transaction while you verify your changes will block other calls to the table(s)!

I always recommend that you are wrapping calls in transactions if you are touching prod data. I only left the WHERE clause of my update query off once in my life before I started doing that.

Re:Salesforce enables ‘modify all’ in user profiles by megous on Saturday May 18, 2019 @08:15AM (#19946987)
If you fear this, you can put it into script like this:

BEGIN; UPDATE... SELECT for verification ROLLBACK;

And then just change ROLLBACK to COMMIT, after you're sattisfied. There's no need to do it interactively.

Re:Salesforce enables ‘modify all’ in user profiles by PowerfulWizard on Friday May 17, 2019 @09:53PM (#19945116)
That is smart, I would add "limit 2" to a single row update, so if it returns 2 rows updated I know it was wrong.
Re:Salesforce enables ‘modify all’ in user profiles by throwaway287391 on Saturday May 18, 2019 @02:51AM (#19946104)
> * Enforce style rules with a linter/test, like "UPDATE must have a LIMIT"

As someone who has never had access to a DB with any serious number of users, can you explain this one further? What if you really do want to update every row? Do you just do LIMIT INT_MAX or the like, and just force people to write that so that they always know they're updating the entire table? Or are you saying you should only ever use UPDATE on a known finite (and small?) number of rows?

Re:Salesforce enables ‘modify all’ in user profiles by londons_explore on Saturday May 18, 2019 @03:19AM (#19946183)
Updating every row is usually a bad idea anyway. That means every row needs to be rewritten, which involves reading and writing all data in the table. That will take locks which mean old data needs to be kept (in case of a transaction abort), doubling disk usage. Since half of rows are now dead, all other queries to the table will take double the disk access time.

Basically, if your table is over a few gigabytes, updating every row in one query on a production instance is a really bad plan.

Re:Salesforce enables ‘modify all’ in user profiles by CydeWeys on Saturday May 18, 2019 @10:10AM (#19947445)
So how do you make the change then? Do SQL dialects provide built-in tools to do an UPDATE to a large table in a saner way, or do you end up having to write an application to do so?
Re:Salesforce enables ‘modify all’ in user profiles by groceryheist on Saturday May 18, 2019 @03:01AM (#19946132)
I think it might just be like a psychological thing to try to prevent mistakes. Like a dialogue box asking "Sure?" before you delete your harddrive.
Re:Salesforce enables ‘modify all’ in user profiles by joatmon-snoo on Saturday May 18, 2019 @03:29AM (#19946206)
It's the notion of a staggered rollout. You should never initiate a global change without first validating it on some small, controlled-impact subset.
Re:Salesforce enables ‘modify all’ in user profiles by gknoy on Friday May 17, 2019 @08:33PM (#19944844)
I'm sorry for being a SQL noob. Can you elaborate on what is wrong with this, and what would be the way to write it without causing the scale of problem described in the OP?
Re:Salesforce enables ‘modify all’ in user profiles by fazzone on Friday May 17, 2019 @08:41PM (#19944883)
The problem is that the condition is parsed as

  (user=671156 AND permission=16 AND org=101) OR 102
The right way is to use something like

  org IN (101, 102)
Re:Salesforce enables ‘modify all’ in user profiles by jimnotgym on Saturday May 18, 2019 @04:03AM (#19946298)
There are lots of good answers already posted, but if I can make a further suggestion...

It is often worth running a SELECT on the WHERE clause you are about to use for your UPDATE. That way you can make sure only a limited amount of data comes back before you launch something catastrophic.

Re:Salesforce enables ‘modify all’ in user profiles by brianwu02 on Friday May 17, 2019 @08:39PM (#19944870)
the last OR statement "OR 102" will evaluate true.

It should be

    UPDATE permissions SET allow = 1 WHERE user=671156 AND permission=16 AND org=101 OR org=102;
Re:Salesforce enables ‘modify all’ in user profiles by slavik81 on Friday May 17, 2019 @09:36PM (#19945054)
You and fazzone have posted different answers. I'm a little unclear on which matches the original intent, but your where clause is equivalent to:

  (user=671156 AND permission=16 AND org=101) OR (org=102)
Re:Salesforce enables ‘modify all’ in user profiles by ummonk on Friday May 17, 2019 @09:47PM (#19945092)
That is still wrong and would apply to everyone in org 102
Re:Salesforce enables ‘modify all’ in user profiles by conro1108 on Saturday May 18, 2019 @03:03AM (#19946137)
Applying to everyone in org 102 is the intended behavior no? The slip-up would be the 'OR 102' which would just evaluate to true.
Re:Salesforce enables ‘modify all’ in user profiles by larkeith on Saturday May 18, 2019 @05:01AM (#19946425)
The example query is supposed to match a single account, not an org.
Re:Salesforce enables ‘modify all’ in user profiles by snaky on Saturday May 18, 2019 @10:47AM (#19947671)
> In addition to the SQL-standard privilege system available through GRANT, tables can have row security policies that restrict, on a per-user basis, which rows can be returned by normal queries or inserted, updated, or deleted by data modification commands. This feature is also known as Row-Level Security

https://www.postgresql.org/docs/11/ddl-rowsecurity.html