Skip to content
\n

authenticate() could throw an AuthenticationFailedError, and the client can catch this to show a login form.

\n

Currently it doesn't work, the client receives a generic Error object. The docs confirm this: only \"Error and its well-known subclasses are passed as-is\"

","upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"

In general, we intentionally do not support custom pass-by-value types. All custom types must be pass-by-reference. This includes custom Error subclasses.

\n

The reason for this is because custom serializable types have proven to be a security disaster in Java and other languages. It's just too easy to create a custom serializable type which inadvertently allows an attacker to trick the remote party into doing unsafe things, by sending an instance of that type when it isn't expected.

\n

What we can do, though, is:

\n\n

I had intended to do both of these things but it looks like it's still marked as a TODO in the code.

\n

With all that said, I would probably recommend having authenticate() return null on failure, or something like that. It's a style preference but I generally recommend throwing exceptions only for unexpected problems for which there's nothing you can do -- not for situations where you want the client to take a specific action, like redirecting to a login page.

","upvoteCount":1,"url":"https://github.com/cloudflare/capnweb/discussions/45#discussioncomment-14513995"}}}
Discussion options

You must be logged in to vote

In general, we intentionally do not support custom pass-by-value types. All custom types must be pass-by-reference. This includes custom Error subclasses.

The reason for this is because custom serializable types have proven to be a security disaster in Java and other languages. It's just too easy to create a custom serializable type which inadvertently allows an attacker to trick the remote party into doing unsafe things, by sending an instance of that type when it isn't expected.

What we can do, though, is:

  • Override error.name to match the custom type ("AuthenticationFailedError") even if the class becomes just Error.
  • Serialize any additional own properties placed on the error object, s…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@joostn
Comment options

@kentonv
Comment options

Answer selected by joostn
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants