Better HN
topnewbestaskshowjobs
Log inSign up

nmadden

511 karma · joined Jun 20, 2015 (11y ago) · 248 submissions

Author API Security in Action - https://www.manning.com/books/api-security-in-action

https://neilmadden.blog/about

[ my public key: https://keybase.io/neilmadden; my proof: https://keybase.io/neilmadden/sigs/QfrQtB7H1Ni4rhaFpENFBtqqCd-VYDYXqYHKRfojHnk ]

Submissions

comment 5y ago · link · parent

Don’t you just return links that refer to the other service? (ie absolute URLs). That is kind of the point of hyperlinks: the service hosting a resource can change, and you just change the links you serve rather than changing lots of hard-coded clients.

comment 5y ago · link · parent

Right. SCRAM is only secure if you already have a secure channel - eg if you’ve already done a TLS handshake with certificate auth. A PAKE is secure on its own. However, IMO most people saying they need a PAKE could use SCRAM instead and actually have a chance of understanding what they have deployed.

comment 5y ago · link · parent

Digest should just die. It’s a terrible standard that makes it essential impossible to store passwords securely on the server.

comment 5y ago · link · parent

Well SHA-3 is a hash function, and indeed somewhat slow in software. But the team have since enormously expanded the primitives based on the same core design, with much better performance: https://keccak.team/sw_performance.html

You can also look at things like the Strobe framework, which builds essentially all of its symmetric crypto out of the SHA-3 core permutation: https://strobe.sourceforge.io/

comment 5y ago · link · parent

Aside from the various technical reasons others have given, I would like to say please have a look at the underlying design of SHA-3 - it’s really elegant, with so many applications beyond just hash functions. Ironically, I feel like SHA-3 should obsolete block ciphers like AES more than it obsoletes SHA-2.

https://keccak.team/sponge_duplex.html

comment 5y ago · link · parent

Yes - technically you don't need to escape : in most places, but many implementations will do so anyway as they use a single encoding method for all URI components. (And if you don't encode these things where they are not required then you'll soon find lots of downstream systems that break).

comment 5y ago · link · parent

Older CBC cipher suites padded to the next multiple of 16 bytes (for AES). TLS 1.3 doesn’t support these anymore but added a more general padding mechanism [1]. I don’t know whether any browser actually uses it though.

[1]: https://datatracker.ietf.org/doc/html/rfc8446#section-5.4

comment 5y ago · link · parent

(Author of the post here).

My point is that you can easily make this a complete non-issue by increasing the entropy of the token. 96-bit tokens are 16 characters in base64url - just 3 more characters than the 64-bit tokens used by Waterken, yet with a token space 4 billion times as large. By way of contrast, Google Docs URLs include a random string that is over 40 characters long.

comment 5y ago · link · parent

Two points:

Your calculations assume that attackers are interested in brute forcing one particular token. But if your app issues a lot of tokens then it becomes easier for an attacker to find some valid token.

For example, if you issue a billion tokens and allow a thousand requests per second then I can find one of those tokens in about 100 days. Is that realistic? Maybe not, but it’s a lot lower than 250k years.

The second point is that I’ve several times in my life seen code that logs a hash of a security token to allow easy correlation of requests. Such a hashed log is then vulnerable to offline brute force attacks with very many more than a million guesses per second.

comment 5y ago · link · parent

Your argument has gone from “this is impossible with capabilities” to “this doesn’t scale” to “nobody uses design patterns”.

You are confusing DI frameworks (often terrible) with the general concept of dependency injection, which is in fact extremely widely used.

comment 5y ago · link · parent

The beauty of object-capability security is that it completely aligns with normal object-oriented design. So you can always recast these discussions to not be about security: how would I inject any other new dependency I needed without changing the API of all intermediaries? And there is a whole literature of design patterns for doing this.

comment 5y ago · link · parent

One of the foundations of object-capability security is memory safety, so loading arbitrary native code does subvert that. You can get around this by, for example, requiring native code to be loaded in a separate process. As you say, a capability OS and/or CPU architecture [1] is able to confine native code.

> isn’t it a problem if a module’s permissions may increase without explicit input from the module’s user (transitive or otherwise)?

Exactly right.

[1]: https://www.cl.cam.ac.uk/research/security/ctsrd/cheri/

comment 5y ago · link · parent

Typically libraries don’t directly load one another. The language runtime does this.

comment 5y ago · link · parent

> If a library needs access to a remote service, you have to open the socket yourself and pass that in, and the library then needs to plumb it through the whole stack manually to the point where it's needed.

You don't need to do this. There are a variety of ways to handle this, just as you would any other kind of dependency injection:

1. Design libraries to actually be modular so that dependencies (including capabilities) can be injected just where they are needed.

2. Pass in a factory object that lets the library construct sockets as and when it needs them. You can then enforce any arbitrary checks at the point of creating the socket. (This is much more flexible than a Java policy file).

3. Use a powerbox pattern [1] to allow the user to be directly asked each time the library attempts to open a socket. This is not always good UX, but sometimes it is the right solution.

> If the library develops a need for a new permission then the API must change and again, the whole thing has to be manually plumbed through.

Capturing permission requirements in the API is a good thing! With the stack walking/policy based approach I won't know the library needs a new permission until some library call suddenly fails at runtime.

[1]: http://wiki.erights.org/wiki/Powerbox

comment 5y ago · link · parent

Are you aware of the history of object-capability programming languages? There are multiple actual demonstrations of real-world ocaps programming languages and projects built with them:

* The (now defunct) E programming language: http://erights.org and Joule: https://en.wikipedia.org/wiki/Joule_(programming_language) * Pony: https://www.ponylang.io * Monte: http://www.monte-language.org * The Midori project at Microsoft: http://joeduffyblog.com/2015/11/10/objects-as-secure-capabil...

It's actually not at all unworkable to use object-capability for large programs. In fact, one of the main benefits of ocaps is how well it aligns with well-established good software design principles such as dependency injection, avoiding singletons, avoiding global mutable state, and so on.

comment 5y ago · link · parent

That’s just the first example. As the author of that series writes, most of the exploits are not due to memory corruption. Most are confused deputy attacks where privileged code can be tricked into performing dangerous operations.

comment 5y ago · link · parent

The File example is a good illustration of why Java is _not_ a capability-secure language. Every File object in Java has a getParentFile() method that allows you to navigate up the hierarchy right to the root and then from there access every file on the filesystem. Java’s standard library is full of these kinds of design flaws. So in practice you can only apply capability-based thinking to small subsets of a codebase and have to fallback on the (much weaker) stack walking checks if you want strong isolation.

The problem with Java’s stack walking is that it is too complex and too easy to find privileged code that can be coaxed into performing unintended operations. There are plenty of old write ups of Java sandbox bypass bugs due to this, eg http://benmmurphy.github.io/blog/2015/10/21/zdi-13-075-2013-...

comment 5y ago · link · parent

Exactly. What usually happens in capability systems is that the main() method gets all the capabilities (or whatever capabilities the user allowed it) and then does dependency injection to distribute those to other components. No need for complex stack-based authentication or policy rule evaluation.

Indeed, if you look at the history of Java sandbox escapes they are largely confused deputy attacks: some privileged code source can be tricked into doing something it shouldn’t do.

comment 5y ago · link · parent

Oracle’s own secure coding guidelines for Java [1] actually now recommend adopting a capability-based approach rather than relying on SecurityManager:

> FUNDAMENTALS-5: Minimise the number of permission checks Java is primarily an object-capability language. SecurityManager checks should be considered a last resort.

(Note: quite a lot of Java’s standard library is not designed along object-capability lines so you should take this advice with a pinch of salt).

[1]: https://www.oracle.com/java/technologies/javase/seccodeguide...

comment 5y ago · link · parent

For cookies... not for Basic Auth.

comment 5y ago · link · parent

Right - there is no way for the server to tell a browser to stop sending basic auth credentials.

comment 5y ago · link · parent

“none” has never been a mandatory algorithm. https://tools.ietf.org/html/rfc7518#section-3.1

comment 6y ago · link · parent

> They can be semantic and in practice are used semantically, especially in nominal type systems. It depends on the programming language how much they enforce though, but even if you don't enforce anything names carry meaning [...]

But grammar productions are also named and grammars are also designed to capture semantic notions. The syntax is after all intended to convey meaning.

comment 6y ago · link · parent

> I would certainly hope that a type "checker" returns a more detailed representation of a program than a parse tree - one in which all expressions are typed and ill-typed expressions cannot be represented.

Do you have an example of this? It is not my experience of compiler intermediate representations or ASTs that they have this property.

> But since we all understand types and types can cover all the cases we've managed to find so far, I'd stick to types unless and until we can demonstrate a need for something else.

This doesn’t really argue with anything I wrote in the article. (Although I’d argue that nobody strictly “sticks to types” as their sole way to enforce correctness).

> trying to put types on those APIs is the easiest way to see that they're the wrong abstraction

I’m not sure I’d say it’s the easiest, but it certainly helps. I love Haskell as a language, primarily because it has a lovely set of well-designed abstractions. It’s clear the design of those abstractions were guided by types and benefit from that. Many of them remain good abstractions when translated to untyped languages.

comment 6y ago · link · parent

> I see, it's an interesting line of thought but I think trying to move type checking into the grammar is fundamentally a bad idea. You don't want to mix grammar and semantics because that's not how people think about code.

I know that it’s common to refer to type checking as “semantic analysis”, but the logician in me is not happy. There’s nothing inherently more “semantic” about types compared to grammars. As Benjamin Pierce says [1]:

> A type system is a syntactic method for enforcing levels of abstraction in programs.

(Emphasis mine).

> That said I agree that it is interesting to see what the 'parse, don't validate' approach to type checking would be, but I think it should still take place on the type level.

You can certainly write parsers at the type level, but that doesn’t change the fundamental fact that a type checker is a validator. To change a type checker into a parser it would have to output a representation which makes invalid states impossible to represent. From a programmer’s point of view (not the compiler writer), this means that the actual compiled object code would have to have this property. I can see a couple of possible ways you could do this:

- the compiled object code enforces invariants using dynamic checks provided by the runtime/processor - the type-checker outputs something like proof-carrying code [2] that can be rigorously checked prior to execution to ensure the illegal states removed by the type system cannot be recreated.

[1]: https://www.cis.upenn.edu/~bcpierce/tapl/

[2]: https://en.wikipedia.org/wiki/Proof-carrying_code

comment 6y ago · link · parent

Thanks. For what it's worth, the flow of thought was the following:

1. The original "parse, don't validate" essay clearly describes why parsers are preferable to validators.

2. It uses a type system to make illegal states unrepresentable in a programming language - but a type system is a validator under its own terminology.

3. What would a parser-like approach to solving the problem look like?

I believe that actually adjusting the programming language grammar (and thus the actual parser) is clearly a parser approach to solving the problem. Abstraction is also, to me, a parser-like approach to solving the problem - it transforms code that allows illegal states into code that enforces particular invariants. I probably didn't make those connections explicit enough in the blog.

Perhaps the diversion into object-capabilities is a bit off the track, but I found it an interesting connection at least. (And frankly, I'm usually close to the sole audience of my blog so I better make it interesting for me!)

Edit: formatting

comment 6y ago · link · parent

The browser vendors have been looking at this problem for a long time. See https://blog.mozilla.org/security/2020/01/09/crlite-part-1-a... for example (bloom filters included).

comment 6y ago · link · parent

I use the same technique in my book to show how a REST API can be used to exploit XSS even it it always produces and consumes only valid JSON: https://livebook.manning.com/book/api-security-in-action/cha...

comment 6y ago · link · parent

No, the statements in Gödel’s proofs are not paradoxes.

Substitutions of variables are not the same as interpretations. The interpretation tells you what the nonlogical symbols like *, +, ^, 1, 2, 3 etc mean.

comment 6y ago · link · parent

It’s not so much that they’re neither true nor false (they’re not paradoxes), but that they can be true in some interpretations and false in others. I wrote up some notes about this here: https://neilmadden.blog/2020/11/17/some-incomplete-thoughts-...
1
56789