Glance.prototype.serveRequest = function Glance$serveRequest (req, res) {
  var request = {}
  var self = this

  request.fullPath = path.join(
    self.dir,
    decodeURIComponent(parse(req.url).pathname)
  )

  request.ip = req.socket.remoteAddress
  request.method = req.method.toLowerCase()
  request.response = res

  // prevent traversing directories that are parents of the root
  if (request.fullPath.slice(0, self.dir.length) !== self.dir) {
    return self.emit('error', 403, request, res)
  }

  if (request.method !== 'get') {
    return self.emit('error', 405, request, res)
  }

  if (self.nodot && /^\./.test(path.basename(request.fullPath))) {
    return self.emit('error', 404, request, res)
  }

  fs.stat(request.fullPath, statFile)

  function statFile (err, stat) {
    if (err) {
      return self.emit('error', 404, request, res)
    }

    if (!stat.isDirectory()) {
      self.emit('read', request)

      return filed(request.fullPath).pipe(res)
    }

    if (self.hideindex) {
      return self.emit('error', 403, request, res)
    }

    if (!self.indices || !self.indices.length) {
      return listFiles()
    }

    var indices = self.indices.slice()

    findIndex(indices.shift())

    function findIndex (indexTest) {
      fileExists(path.join(request.fullPath, indexTest), check)

      function check (hasIndex) {
        if (hasIndex) {
          req.url = req.url + '/' + indexTest

          return self.serveRequest(req, res)
        }

        if (!indices.length) {
          return listFiles()
        }

        findIndex(indices.shift())
      }
    }

    function listFiles () {
      var listPath = request.fullPath.replace(/\/$/, '')

      res.writeHead(200, RESPONSE_HEADERS)
      htmlls(listPath, {hideDot: self.nodot}).pipe(res)

      return self.emit('read', request)
    }
  }
}
The software uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the software does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.