Settings

Theme

Property-Based Testing Caught a Security Bug I Never Would Have Found

kiro.dev

62 points by nslog 3 months ago · 39 comments

Reader

philipwhiuk 3 months ago

> We write unit tests for the happy path, maybe a few edge cases we can imagine, but what about the inputs we'd never consider? Many times we assume that LLMs are handling these scenarios by default,

Do we?

  • RGamma 3 months ago

    I've seen companies advertise with LLM generated claims (~Best company for X according to ChatGPT), I've seen (political) discussions being held with LLM opinions as "evidence".

    So it's pretty safe to say some (many?) attribute inappropriate credence to LLM outputs. It's eating our minds.

  • bluGill 3 months ago

    The original claim for TDD is your write tests for all your edge cases. It doesn't matter about inputs you didn't consider because they are covered in the edge. If you can only accept inputs from 2-7 (inclusive) you check 1,2,7,8 - if those pass you assume the rest work.

    • Cpoll 3 months ago

      You forgot 0, -1, null, "1".

      • bluGill 3 months ago

        Since I work in a strongly typed languages the last two will fail to compile and are thus not worth the bother - those who don't have that luxury of course need to test the edge cases that apply to them. The first are maybe, in my experience they are rarely a problem, but we need to go from the abstract to the particular algorithm before we can have a discussion on if they are potentially a problem or not.

  • sevensor 3 months ago

    What’s interesting to me about this, reckless as it is, is that the conversation has begun to shift toward balancing LLMs with rigorous methods. These people seem to be selling some kind of AI hype product backed by shoddy engineering, and even they are picking up on the vibe. I think this is a really promising sign for the future.

  • bpt3 3 months ago

    When "we" = "developers we imagined when using LLMs to generate this marketing slop based on a contrived scenario", then sure!

mhitza 3 months ago

Technically a property based test caught the issue.

What I've found surprising is that the __proto__ string is a fixed set from the strings sampling set. Whereas I'd have expected the function to return random strings in the range given.

But maybe that's my biased expectation being introduced to property-based testing with random values. It also feels like a stretch to call this a property-based test, because what is the property "setters and getters that work"? Cause I expect that from all my classes.

  • arnsholt 3 months ago

    Good PBT code doesn't simply generate values at random, they skew the distributions so that known problematic values are more likely to appear. In JS "__proto__" is a good candidate for strings as shown here, for floating point numbers you'll probably want skew towards generating stuff like infinities, nans, denormals, negative zero and so on. It'll depend on your exact domain.

Piraty 3 months ago

It's always good to write tests with the "The Enterprise Developer from Hell" in mind: https://fsharpforfunandprofit.com/posts/property-based-testi...

  • nslogOP 3 months ago

    This is a great talk. More technical videos should be done from the basics like this.

sublinear 3 months ago

> Is this exploitable? No. ... JSON.stringify knows to skip the __proto__ field. ... However, refactors to the code could ... [cause] subtle incorrectness and sharp edge cases in your code base.

So what? This line of what-if reasoning is so annoying especially when it's analysis for a language like javascript. There's no vulnerability found here and most web developers are well aware of the risky parts of the language. This is almost as bad as all the insane false positives SAST scans dump on you.

Oh I'm just waiting to get dogpiled by people who want to tell me web devs are dumber than them and couldn't possibly be competent at anything.

  • oncallthrow 3 months ago

    > most web developers are well aware of the risky parts of the language

    In my experience this really isn’t true. Most web developers I know are not familiar (enough) with prototype pollution.

    By the way, this isn’t because they are “dumb”. It’s the tool’s fault, not the craftsman’s, in this case. Prototype pollution is complicated and surprising

  • yakshaving_jgt 3 months ago

    > most web developers are well aware of the risky parts of the language

    I don't think this is true, and I think that's supported by the success of JavaScript: The Good Parts.

    It would be unfair to characterise a lack of comprehensive knowledge of JavaScript foot-guns as general incompetence.

  • jgalt212 3 months ago

    > insane false positives SAST scans dump on you

    Great LLM use case: Please explain to the box ticking person why these "insane false positives SAST" are false and / or of no consequence.

koakuma-chan 3 months ago

This kind of bug would never have happened if you used a proper programming language like Rust.

  • kittoes 3 months ago

    This just can't be your answer to everything... the article clearly stated that they're developing a client application for browsers. Rust advocates like yourself are really doing more harm than good by ignoring real world constraints.

    • hansvm 3 months ago

      To be fair, this particular issue wouldn't have happened in C, Python, Forth, Zig, or a host of other languages. String-based weirdness is something of a JS issue.

      • cogman10 3 months ago

        This particular issue looks to be pretty uniquely a javascript problem. I don't even think hyper flexible languages like Ruby would ultimately experience this sort of problem.

        • mananaysiempre 3 months ago

          Ruby can experience a similar problem[1], but that’s largely because its metaobject protocol draws no distinction between a read-only field and a zero-argument method. Python’s model does not have that issue (at the cost of significant complexity) and it is about as flexible as Ruby’s ultimately. (Python’s more rigid syntax is not relevant either way.)

          [1] https://news.ycombinator.com/item?id=33155527

    • koakuma-chan 3 months ago

      You can use Rust to develop client application for browsers. Check out dioxus.

      • regular_trash 3 months ago

        Rust is an unergonomic language that slows development in the general case (because it has lots of arcane syntax and rules, and people generally don't know it). Suggesting it as the "obvious" choice ignores the tradeoffs that come with adopting it for a project.

mananaysiempre 3 months ago

TL;DR: obj[key] with user-controlled key == "__proto__" is a gift that keeps on giving; buy our AI tool that will write subtle vulnerabilities like that which you yourself won’t catch in review but then it will also write some property-based tests that maybe will

  • fireflash38 3 months ago

    Don't forget you can use AI to turn a 50 word blog post into a 2,000 word one!

    • mirthturtle 3 months ago

      For real. The bullet-point summary at the beginning with a "Why this matters for..." immediately followed by, "This isn't just a theoretical exercise—it's a real example of..." Dead giveaways.

    • raphting 3 months ago

      Exactly this! AI fluff all over in that article.

  • toobulkeh 3 months ago

    It also talks about using PBT and Randomness for some reason. This is clearly just a test value of a non-AI library written by a human.

    My take away is “don’t write your own input tests, use a library”. The rest is AI-slip

  • nslogOP 3 months ago

    Didn't react just have basically the same vuln

    • mananaysiempre 3 months ago

      The code in TFA is, by a hair’s breadth, not actually vulnerable, as long as the type signature of the function is obeyed. React spinned the same gun in the game of Russian roulette but was less lucky.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection