[ 
https://issues.apache.org/jira/browse/THRIFT-6259?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jens Geyer updated THRIFT-6259:
-------------------------------
    Description: 
{{lib/nodejs/lib/thrift/json_protocol.js}}, at the end of 
{{TJSONProtocol.prototype.skip}} (line 880):

{code:javascript}
default:
  throw new Error("Invalid type: " + type);
{code}

Every other error path in the protocol raises {{Thrift.TProtocolException}}, 
which carries a {{TProtocolExceptionType}} a caller can switch on. Here a 
peer-supplied type name that the protocol does not know produces a plain 
{{Error}} instead, so a server whose error handling is written against 
{{TProtocolException}} does not recognise it.

It is reachable from ordinary input: a message whose struct contains a field 
the receiver does not declare goes through {{skip()}}, and a JSON value naming 
a type the switch has no case for reaches the default arm:

{code:json}
{"1":{"bogus":5}}
{code}

h2. Suggested fix

Throw

{code:javascript}
new Thrift.TProtocolException(Thrift.TProtocolExceptionType.INVALID_DATA, 
"Invalid type: " + type);
{code}

matching the {{DEPTH_LIMIT}} raises a few lines above ({{:801}}, {{:815}}), 
which already use {{Thrift.TProtocolException}}. Two other protocol-level 
{{throw new Error}} sites in this file are the same question and could be 
changed with it: {{:459}} ("Malformed JSON input, no opening bracket") and 
{{:511}} ("Wrong thrift protocol version"). The {{writeString}}/{{writeBinary}} 
argument checks at {{:368}} and {{:423}} are caller mistakes rather than 
protocol errors and can stay as they are.

_Drafted with AI assistance (Claude Opus 5); reviewed and filed by Jens Geyer._

  was:
{{lib/nodejs/lib/thrift/json_protocol.js}}, at the end of 
{{TJSONProtocol.prototype.skip}} (line 880):

{code:javascript}
default:
  throw new Error("Invalid type: " + type);
{code}

Every other error path in the protocol raises {{Thrift.TProtocolException}}, 
which carries a {{TProtocolExceptionType}} a caller can switch on. Here a 
peer-supplied type name that the protocol does not know produces a plain 
{{Error}} instead, so a server whose error handling is written against 
{{TProtocolException}} does not recognise it.

It is reachable from ordinary input: a message whose struct contains a field 
the receiver does not declare goes through {{skip()}}, and a value such as 
{{{}{"1":{"bogus":5}}{}}} names a type the switch has no case for.

h2. Suggested fix

Throw

{code:javascript}
new Thrift.TProtocolException(Thrift.TProtocolExceptionType.INVALID_DATA, 
"Invalid type: " + type);
{code}

matching the {{DEPTH_LIMIT}} raises a few lines above ({{:801}}, {{:815}}), 
which already use {{Thrift.TProtocolException}}. Two other protocol-level 
{{throw new Error}} sites in this file are the same question and could be 
changed with it: {{:459}} ("Malformed JSON input, no opening bracket") and 
{{:511}} ("Wrong thrift protocol version"). The {{writeString}}/{{writeBinary}} 
argument checks at {{:368}} and {{:423}} are caller mistakes rather than 
protocol errors and can stay as they are.

_Drafted with AI assistance (Claude Opus 5); reviewed and filed by Jens Geyer._


> Node.js: TJSONProtocol.skip() throws a plain Error for an unknown type name
> ---------------------------------------------------------------------------
>
>                 Key: THRIFT-6259
>                 URL: https://issues.apache.org/jira/browse/THRIFT-6259
>             Project: Thrift
>          Issue Type: Bug
>          Components: Node.js - Library
>            Reporter: Jens Geyer
>            Priority: Minor
>
> {{lib/nodejs/lib/thrift/json_protocol.js}}, at the end of 
> {{TJSONProtocol.prototype.skip}} (line 880):
> {code:javascript}
> default:
>   throw new Error("Invalid type: " + type);
> {code}
> Every other error path in the protocol raises {{Thrift.TProtocolException}}, 
> which carries a {{TProtocolExceptionType}} a caller can switch on. Here a 
> peer-supplied type name that the protocol does not know produces a plain 
> {{Error}} instead, so a server whose error handling is written against 
> {{TProtocolException}} does not recognise it.
> It is reachable from ordinary input: a message whose struct contains a field 
> the receiver does not declare goes through {{skip()}}, and a JSON value 
> naming a type the switch has no case for reaches the default arm:
> {code:json}
> {"1":{"bogus":5}}
> {code}
> h2. Suggested fix
> Throw
> {code:javascript}
> new Thrift.TProtocolException(Thrift.TProtocolExceptionType.INVALID_DATA, 
> "Invalid type: " + type);
> {code}
> matching the {{DEPTH_LIMIT}} raises a few lines above ({{:801}}, {{:815}}), 
> which already use {{Thrift.TProtocolException}}. Two other protocol-level 
> {{throw new Error}} sites in this file are the same question and could be 
> changed with it: {{:459}} ("Malformed JSON input, no opening bracket") and 
> {{:511}} ("Wrong thrift protocol version"). The 
> {{writeString}}/{{writeBinary}} argument checks at {{:368}} and {{:423}} are 
> caller mistakes rather than protocol errors and can stay as they are.
> _Drafted with AI assistance (Claude Opus 5); reviewed and filed by Jens 
> Geyer._



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to