CVE-2023-50710 (published 2023-12-14T18:15Z)

Hono is a web framework written in TypeScript. Prior to version 3.11.7, clients may override named path parameter values from previous requests if the application is using TrieRouter. So, there is a risk that a privileged user may use unintended parameters when deleting REST API resources. TrieRouter is used either explicitly or when the application matches a pattern that is not supported by the default RegExpRouter. Version 3.11.7 includes the change to fix this issue. As a workaround, avoid using TrieRouter directly.

CVSS v3 base score: 4.3, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:N)

Weakness information:
cwe_id: CWE-94
cwe_name: Improper Control of Generation of Code ('Code Injection')
description: The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
extended_description: 
            When a product allows a user's input to contain code syntax, it might be possible for an attacker to craft the code in such a way that it will alter the intended control flow of the product. Such an alteration could lead to arbitrary code execution.
            Injection problems encompass a wide variety of issues -- all mitigated in very different ways. For this reason, the most effective way to discuss these weaknesses is to note the distinct features which classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed. The most classic instantiations of this category of weakness are SQL injection and format string vulnerabilities.
         
         

Fix information:
repo_url: https://github.com/honojs/hono
commit_details: repo_url: https://github.com/honojs/hono
author: Yusuke Wada
author_date: 2023-12-14 10:21:02+09:00
msg: Merge pull request from GHSA-f6gv-hh8j-q8vq

* fix(trie-router): don't remain with the values of named param

* denoify

* fix: don't share `params`

* denoify
repository: repo_url: https://github.com/honojs/hono
repo_name: honojs/hono
description: Web framework built on Web Standards
repo_language: TypeScript
owner: honojs
file_changes: filename: node.ts
change_type: ModificationType.MODIFY
diff: @@ -5,12 +5,15 @@ import { splitPath, splitRoutingPath, getPattern } from '../../utils/url.ts'
 
 type HandlerSet<T> = {
   handler: T
-  params: Record<string, string>
   possibleKeys: string[]
   score: number
   name: string // For debug
 }
 
+type HandlerParamsSet<T> = HandlerSet<T> & {
+  params: Record<string, string>
+}
+
 export class Node<T> {
   methods: Record<string, HandlerSet<T>>[]
 
@@ -26,7 +29,7 @@ export class Node<T> {
     this.name = ''
     if (method && handler) {
       const m: Record<string, HandlerSet<T>> = {}
-      m[method] = { handler, params: {}, possibleKeys: [], score: 0, name: this.name }
+      m[method] = { handler, possibleKeys: [], score: 0, name: this.name }
       this.methods = [m]
     }
     this.patterns = []
@@ -74,7 +77,6 @@ export class Node<T> {
 
     const handlerSet: HandlerSet<T> = {
       handler,
-      params: {},
       possibleKeys,
       name: this.name,
       score: this.order,
@@ -87,12 +89,17 @@ export class Node<T> {
   }
 
   // getHandlerSets
-  private gHSets(node: Node<T>, method: string, params: Record<string, string>): HandlerSet<T>[] {
-    const handlerSets: HandlerSet<T>[] = []
+  private gHSets(
+    node: Node<T>,
+    method: string,
+    params: Record<string, string>
+  ): HandlerParamsSet<T>[] {
+    const handlerSets: HandlerParamsSet<T>[] = []
     for (let i = 0, len = node.methods.length; i < len; i++) {
       const m = node.methods[i]
-      const handlerSet = m[method] || m[METHOD_NAME_ALL]
+      const handlerSet = (m[method] || m[METHOD_NAME_ALL]) as HandlerParamsSet<T>
       if (handlerSet !== undefined) {
+        handlerSet.params = {}
         handlerSet.possibleKeys.map((key) => {
           handlerSet.params[key] = params[key]
         })
@@ -103,7 +110,7 @@ export class Node<T> {
   }
 
   search(method: string, path: string): [[T, Params][]] {
-    const handlerSets: HandlerSet<T>[] = []
+    const handlerSets: HandlerParamsSet<T>[] = []
 
     const params: Record<string, string> = {}
     this.params = {}
@@ -126,11 +133,9 @@ export class Node<T> {
           if (isLast === true) {
             // '/hello/*' => match '/hello'
             if (nextNode.children['*']) {
-              handlerSets.push(
-                ...this.gHSets(nextNode.children['*'], method, { ...params, ...node.params })
-              )
+              handlerSets.push(...this.gHSets(nextNode.children['*'], method, node.params))
             }
-            handlerSets.push(...this.gHSets(nextNode, method, { ...params, ...node.params }))
+            handlerSets.push(...this.gHSets(nextNode, method, node.params))
           } else {
             tempNodes.push(nextNode)
           }
@@ -144,7 +149,7 @@ export class Node<T> {
           if (pattern === '*') {
             const astNode = node.children['*']
             if (astNode) {
-              handlerSets.push(...this.gHSets(astNode, method, { ...params, ...node.params }))
+              handlerSets.push(...this.gHSets(astNode, method, node.params))
               tempNodes.push(astNode)
             }
             continue

programming_language: TypeScript
filename: node.test.ts
change_type: ModificationType.MODIFY
diff: @@ -89,6 +89,21 @@ describe('Name path', () => {
     expect(res[0][0]).toEqual('get events')
     expect(res[0][1]['location']).toBe('yokohama')
   })
+
+  it('Should not return a previous param value', () => {
+    const node = new Node()
+    node.insert('delete', '/resource/:id', 'resource')
+    const [resA] = node.search('delete', '/resource/a')
+    const [resB] = node.search('delete', '/resource/b')
+    expect(resA).not.toBeNull()
+    expect(resA.length).toBe(1)
+    expect(resA[0][0]).toEqual('resource')
+    expect(resA[0][1]).toEqual({ id: 'a' })
+    expect(resB).not.toBeNull()
+    expect(resB.length).toBe(1)
+    expect(resB[0][0]).toEqual('resource')
+    expect(resB[0][1]).toEqual({ id: 'b' })
+  })
 })
 
 describe('Name path - Multiple route', () => {

programming_language: TypeScript
filename: node.ts
change_type: ModificationType.MODIFY
diff: @@ -5,12 +5,15 @@ import { splitPath, splitRoutingPath, getPattern } from '../../utils/url'
 
 type HandlerSet<T> = {
   handler: T
-  params: Record<string, string>
   possibleKeys: string[]
   score: number
   name: string // For debug
 }
 
+type HandlerParamsSet<T> = HandlerSet<T> & {
+  params: Record<string, string>
+}
+
 export class Node<T> {
   methods: Record<string, HandlerSet<T>>[]
 
@@ -26,7 +29,7 @@ export class Node<T> {
     this.name = ''
     if (method && handler) {
       const m: Record<string, HandlerSet<T>> = {}
-      m[method] = { handler, params: {}, possibleKeys: [], score: 0, name: this.name }
+      m[method] = { handler, possibleKeys: [], score: 0, name: this.name }
       this.methods = [m]
     }
     this.patterns = []
@@ -74,7 +77,6 @@ export class Node<T> {
 
     const handlerSet: HandlerSet<T> = {
       handler,
-      params: {},
       possibleKeys,
       name: this.name,
       score: this.order,
@@ -87,12 +89,17 @@ export class Node<T> {
   }
 
   // getHandlerSets
-  private gHSets(node: Node<T>, method: string, params: Record<string, string>): HandlerSet<T>[] {
-    const handlerSets: HandlerSet<T>[] = []
+  private gHSets(
+    node: Node<T>,
+    method: string,
+    params: Record<string, string>
+  ): HandlerParamsSet<T>[] {
+    const handlerSets: HandlerParamsSet<T>[] = []
     for (let i = 0, len = node.methods.length; i < len; i++) {
       const m = node.methods[i]
-      const handlerSet = m[method] || m[METHOD_NAME_ALL]
+      const handlerSet = (m[method] || m[METHOD_NAME_ALL]) as HandlerParamsSet<T>
       if (handlerSet !== undefined) {
+        handlerSet.params = {}
         handlerSet.possibleKeys.map((key) => {
           handlerSet.params[key] = params[key]
         })
@@ -103,7 +110,7 @@ export class Node<T> {
   }
 
   search(method: string, path: string): [[T, Params][]] {
-    const handlerSets: HandlerSet<T>[] = []
+    const handlerSets: HandlerParamsSet<T>[] = []
 
     const params: Record<string, string> = {}
     this.params = {}
@@ -126,11 +133,9 @@ export class Node<T> {
           if (isLast === true) {
             // '/hello/*' => match '/hello'
             if (nextNode.children['*']) {
-              handlerSets.push(
-                ...this.gHSets(nextNode.children['*'], method, { ...params, ...node.params })
-              )
+              handlerSets.push(...this.gHSets(nextNode.children['*'], method, node.params))
             }
-            handlerSets.push(...this.gHSets(nextNode, method, { ...params, ...node.params }))
+            handlerSets.push(...this.gHSets(nextNode, method, node.params))
           } else {
             tempNodes.push(nextNode)
           }
@@ -144,7 +149,7 @@ export class Node<T> {
           if (pattern === '*') {
             const astNode = node.children['*']
             if (astNode) {
-              handlerSets.push(...this.gHSets(astNode, method, { ...params, ...node.params }))
+              handlerSets.push(...this.gHSets(astNode, method, node.params))
               tempNodes.push(astNode)
             }
             continue

programming_language: TypeScript