{"id":18337244,"url":"https://github.com/pillarjs/resolve-path","last_synced_at":"2025-04-06T08:14:31.634Z","repository":{"id":15302383,"uuid":"18032158","full_name":"pillarjs/resolve-path","owner":"pillarjs","description":"Resolve a relative path against a root path with validation","archived":false,"fork":false,"pushed_at":"2024-08-17T07:36:44.000Z","size":58,"stargazers_count":32,"open_issues_count":3,"forks_count":11,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-30T06:08:47.136Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pillarjs.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"express"}},"created_at":"2014-03-23T11:48:21.000Z","updated_at":"2025-01-31T14:05:18.000Z","dependencies_parsed_at":"2024-06-02T17:17:15.406Z","dependency_job_id":"fee796ef-2963-4ac3-a234-7af31c58710b","html_url":"https://github.com/pillarjs/resolve-path","commit_stats":{"total_commits":122,"total_committers":3,"mean_commits":"40.666666666666664","dds":0.09836065573770492,"last_synced_commit":"6842d4a5ffaca3bb4b80c136ff47dd3a6a6c420c"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pillarjs%2Fresolve-path","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pillarjs%2Fresolve-path/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pillarjs%2Fresolve-path/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pillarjs%2Fresolve-path/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pillarjs","download_url":"https://codeload.github.com/pillarjs/resolve-path/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247451667,"owners_count":20940944,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T20:10:34.339Z","updated_at":"2025-04-06T08:14:31.612Z","avatar_url":"https://github.com/pillarjs.png","language":"JavaScript","funding_links":["https://opencollective.com/express"],"categories":[],"sub_categories":[],"readme":"# resolve-path\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Node.js Version][node-image]][node-url]\n[![Linux Build][travis-image]][travis-url]\n[![Windows Build][appveyor-image]][appveyor-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nResolve a relative path against a root path with validation.\n\nThis module would protect against commons attacks like `GET /../file.js`\nwhich reaches outside the root folder.\n\n## Installation\n\nThis is a [Node.js](https://nodejs.org/en/) module available through the\n[npm registry](https://www.npmjs.com/). Installation is done using the\n[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):\n\n```sh\n$ npm install resolve-path\n```\n\n## API\n\n```\nvar resolvePath = require('resolve-path')\n```\n\n### resolvePath(relativePath)\n\nResolve a relative path against `process.cwd()` (the process's current working\ndirectory) and return an absolute path. *This will throw* if the resulting resolution\nseems malicious. The following are malicious:\n\n  - The relative path is an absolute path\n  - The relative path contains a NULL byte\n  - The relative path resolves to a path outside of `process.cwd()`\n  - The relative path traverses above `process.cwd()` and back down\n\n### resolvePath(rootPath, relativePath)\n\nResolve a relative path against the provided root path and return an absolute path.\n*This will throw* if the resulting resolution seems malicious. The following are\nmalicious:\n\n  - The relative path is an absolute path\n  - The relative path contains a NULL byte\n  - The relative path resolves to a path outside of the root path\n  - The relative path traverses above the root and back down\n\n## Example\n\n### Safely resolve paths in a public directory\n\n```js\nvar http = require('http')\nvar parseUrl = require('parseurl')\nvar path = require('path')\nvar resolvePath = require('resolve-path')\n\n// the public directory\nvar publicDir = path.join(__dirname, 'public')\n\n// the server\nvar server = http.createServer(function onRequest (req, res) {\n  try {\n    // get the pathname from the URL (decoded)\n    var pathname = decodeURIComponent(parseUrl(req).pathname)\n\n    if (!pathname) {\n      res.statusCode = 400\n      res.end('path required')\n      return\n    }\n\n    // remove leading slash\n    var filename = pathname.substr(1)\n\n    // resolve the full path\n    var fullpath = resolvePath(publicDir, filename)\n\n    // echo the resolved path\n    res.statusCode = 200\n    res.end('resolved to ' + fullpath)\n  } catch (err) {\n    res.statusCode = err.status || 500\n    res.end(err.message)\n  }\n})\n\nserver.listen(3000)\n```\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/resolve-path.svg\n[npm-url]: https://npmjs.org/package/resolve-path\n[node-image]: https://img.shields.io/node/v/resolve-path.svg\n[node-url]: http://nodejs.org/download/\n[travis-image]: https://img.shields.io/travis/pillarjs/resolve-path/master.svg?label=linux\n[travis-url]: https://travis-ci.org/pillarjs/resolve-path\n[appveyor-image]: https://img.shields.io/appveyor/ci/dougwilson/resolve-path/master.svg?label=windows\n[appveyor-url]: https://ci.appveyor.com/project/dougwilson/resolve-path\n[coveralls-image]: https://img.shields.io/coveralls/pillarjs/resolve-path/master.svg\n[coveralls-url]: https://coveralls.io/r/pillarjs/resolve-path?branch=master\n[downloads-image]: https://img.shields.io/npm/dm/resolve-path.svg\n[downloads-url]: https://npmjs.org/package/resolve-path\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpillarjs%2Fresolve-path","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpillarjs%2Fresolve-path","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpillarjs%2Fresolve-path/lists"}