News for hackers. Stuff that matters.
Re:Things you should do now (2011) by bryanrasmussen on Friday February 19, 2021 @03:11AM (#26190764)
That start ids at a gigantic number idea is great, even though I've never encountered a bug caused by not doing it.
Re:Things you should do now (2011) by boatmansloth on Friday February 19, 2021 @03:48AM (#26190967)
I literally came here to comment that the very first bug I had to chase down in a production system in my first job was caused by this! There was a 'fuzzy' search field available to users and when one input a client's ID number (formatted as NNNNNNN) it was showing results for a different client because NNNNNNN was also the format of the unique ID for records in the database.
Re:Things you should do now (2011) by acdha on Friday February 19, 2021 @11:52AM (#26195024)
I encountered a similar problem recently while migrating an old app. It modeled IDs as 64-bit BIGINT columns (a decision made in the 2000s) and populated them with MySQL’s UUID_SHORT function. This worked fine for over a decade until we migrated to a different MySQL system and started getting conflicts for IDs already existing or not being able to find a row which had just been inserted.

They’d missed the part that UUID_SHORT() returns an unsigned integer and created the column as the default signed integer. MySQL uses an algorithm where the top n bits are based on the server ID, which worked on the old server which had id=1 and never returned a number where the first bit was 1. The new cluster fortunately always did so the problem was immediately identified, but it was confused by one of those bonus MySQL data-destruction features – the way it silently truncated data meant that it was silently truncating new IDs to the same value but the logged value wasn’t in the database at all.

Re:Things you should do now (2011) by tpetry on Friday February 19, 2021 @04:08AM (#26191083)
A better tip would be to use something like time-ordered uuids: You can‘t misuse them for something different and the added bonus is that no one can iterate your db records by just incrementing the url.
Re:Things you should do now (2011) by codingdave on Friday February 19, 2021 @06:44AM (#26192080)
If you are implying that having an un-guessable URL secures your data, you might want to reconsider that approach. Your data should be secured server-side based on the actual auth in your app.
Re:Things you should do now (2011) by derwiki on Friday February 19, 2021 @09:50AM (#26193730)
Not the OP but I read it as “much harder to scrape” than making it Secure. Which has some value.
Re:Things you should do now (2011) by Cthulhu_ on Friday February 19, 2021 @04:15AM (#26191116)
My main gripe with UUIDs at the moment is that they look ugly in urls :/
Re:Things you should do now (2011) by ozim on Friday February 19, 2021 @06:19AM (#26191894)
You should not use your database identifiers in urls anyway.
Re:Things you should do now (2011) by krab on Friday February 19, 2021 @05:03AM (#26191376)
You can encode it to a shorter string if you use larger alphabet. Still, it's 16 bytes of information, so not as short as sequential IDs.

See for example https://pypi.org/project/shortuuid/

    >>> shortuuid.uuid()
    'vytxeTZskVKR7C7WgdSP3d'
Re:Things you should do now (2011) by ivanbakel on Friday February 19, 2021 @05:47AM (#26191665)
Those shorter strings can come with their own caveats. Long-form UUIDs have the nice property of being URL-safe - but IIRC, path pieces in HTTP urls are not meant to be case-sensitive, and browsers have historically tried to "help" by re-casing URLs. For correct semantics, short UUIDs have to go in the request parameters instead.
Re:Things you should do now (2011) by hansvm on Friday February 19, 2021 @10:45AM (#26194331)
Most of the url (including the path pieces) is supposed to be case sensitive unless otherwise specified for a given protocol (and treating e.g. %3A the same as %3a). This should be the most recent RFC on the topic: https://tools.ietf.org/html/rfc3986#section-6.2.2.1
Re:Things you should do now (2011) by account42 on Friday February 19, 2021 @09:37AM (#26193577)
> IRC, path pieces in HTTP urls are not meant to be case-sensitive, and browsers have historically tried to "help" by re-casing URLs.

That would break with any webserver that is serving files from a case-sensitive filesystem. Which is most of them.

Re:Things you should do now (2011) by Deadron on Friday February 19, 2021 @10:36AM (#26194233)
Windows....enough said.
Re:Things you should do now (2011) by pretzelhands on Friday February 19, 2021 @04:43AM (#26191270)
They're not the prettiest sight, yes, but I think anyone who isn't in some way a geek particularly cares about what's actually in URLs.

There's a reason why Apple got away with only showing the hostname of a URL: It doesn't matter to ordinary people. :)

Re:Things you should do now (2011) by genezeta on Friday February 19, 2021 @06:15AM (#26191860)
Not bugs but I've encountered a consequence which is worse than a bug.

In a recent project I arrived at, I started seeing 612 in random places in the code. It was, naturally, the ID of a very specific user. Having an easy ID to remember, it is a temptation for sloppy programmers to just hardcode certain checks against a particular ID instead of following proper procedures. It was a bad project and a bad team, and after some 10 years or so, the code was now flooded with 612 and a couple of other IDs.

Sure, you could avoid such a thing with code revisions and such, but then again it's better to simply not put the temptation in front of the programmers, isn't it?

Re:Things you should do now (2011) by fumblebee on Friday February 19, 2021 @05:42AM (#26191627)
I once debugged a case where the id had left sided zero padding so the whole id length was a fixed number of digits, for example `238974` might be represented as `00238974`.

In a process that joined two tables the match counts were off. Somehow, on one side of the join the id was being converted to an integer and then back to a string, which stripped the zero padding. Meaning that `00238974` was failing to match `238974`.

Sigh.

Re:Things you should do now (2011) by joss82 on Friday February 19, 2021 @03:45AM (#26190947)
Indeed, that and sql syntax errors are solved by using an orm or sql code generator like sql alchemy core.
Re:Things you should do now (2011) by MaxBarraclough on Friday February 19, 2021 @01:07PM (#26195972)
I like that pattern too. I've tried using it in a rather ad-hoc way in C/C++ enums. I suppose the proper solution would be to have a header file, enum_starting_vals.h, to centralise them.