Exemple #1
0
bool RequestURI::process(const VirtualHost *vhost, Transport *transport,
                         const std::string &sourceRoot,
                         const std::string &pathTranslation, const char *url) {
  splitURL(url, m_originalURL, m_queryString);
  m_originalURL = StringUtil::UrlDecode(m_originalURL, false);
  m_rewritten = false;

  auto scriptFilename = transport->getScriptFilename();
  if (!scriptFilename.empty()) {
    // The transport is overriding everything and just handing us the filename
    m_originalURL = scriptFilename;
    if (!resolveURL(vhost, pathTranslation, sourceRoot)) {
      return false;
    }
    if (m_origPathInfo.empty()) {
      // PATH_INFO wasn't filled by resolveURL() because m_originalURL
      // didn't contain it. We set it now, based on PATH_TRANSLATED.
      m_origPathInfo = transport->getPathTranslated();
      if (!m_origPathInfo.empty() &&
          m_origPathInfo.charAt(0) != '/') {
        m_origPathInfo = "/" + m_origPathInfo;
      }
    }
    if (transport->isPathInfoSet()) {
      m_pathInfo =transport->getPathInfo();
    } else {
      m_pathInfo = m_origPathInfo;
    }
    return true;
  }

  // Fast path for files that exist
  if (vhost->checkExistenceBeforeRewrite()) {
    String canon = FileUtil::canonicalize(m_originalURL);
    if (virtualFileExists(vhost, sourceRoot, pathTranslation, canon)) {
      m_rewrittenURL = canon;
      m_resolvedURL = canon;
      return true;
    }
  }

  if (!rewriteURL(vhost, transport, pathTranslation, sourceRoot)) {
    // Redirection
    m_done = true;
    return true;
  }
  if (!resolveURL(vhost, pathTranslation, sourceRoot)) {
    // Can't find
    return false;
  }
  return true;
}
Exemple #2
0
bool RequestURI::process(const VirtualHost *vhost, Transport *transport,
                         const string &sourceRoot,
                         const string &pathTranslation, const char *url) {
  splitURL(url, m_originalURL, m_queryString);
  m_originalURL = StringUtil::UrlDecode(m_originalURL, false);
  m_rewritten = false;

  // Fast path for files that exist
  if (vhost->checkExistenceBeforeRewrite()) {
    String canon(
      Util::canonicalize(m_originalURL.c_str(), m_originalURL.size()),
      AttachString);
    if (virtualFileExists(vhost, sourceRoot, pathTranslation, canon)) {
      m_rewrittenURL = canon;
      m_resolvedURL = canon;
      return true;
    }
  }

  if (!rewriteURL(vhost, transport, pathTranslation, sourceRoot)) {
    // Redirection
    m_done = true;
    return true;
  }
  if (!resolveURL(vhost, pathTranslation, sourceRoot)) {
    // Can't find
    return false;
  }
  return true;
}
bool RequestURI::process(const VirtualHost *vhost, Transport *transport,
                         const string &sourceRoot,
                         const string &pathTranslation, const char *url) {
  splitURL(url, m_originalURL, m_queryString);
  m_originalURL = StringUtil::UrlDecode(m_originalURL, false);

  // Fast path for files that exist
  String canon = Util::canonicalize(string(m_originalURL.c_str(),
                                           m_originalURL.size()));
  String relUrl(canon.charAt(0) == '/' ? canon.substr(1) : canon);
  if (virtualFileExists(vhost, sourceRoot, pathTranslation, relUrl)) {
    m_rewrittenURL = relUrl;
    m_resolvedURL = relUrl;
    PrependSlash(m_resolvedURL);
    return true;
  }

  if (!rewriteURL(vhost, transport, pathTranslation, sourceRoot)) {
    // Redirection
    m_done = true;
    return true;
  }
  if (!resolveURL(vhost, pathTranslation, sourceRoot)) {
    // Can't find
    return false;
  }
  return true;
}
Exemple #4
0
ExceptionOr<Ref<Worker>> Worker::create(ScriptExecutionContext& context, const String& url, JSC::RuntimeFlags runtimeFlags)
{
    ASSERT(isMainThread());

    // We don't currently support nested workers, so workers can only be created from documents.
    ASSERT_WITH_SECURITY_IMPLICATION(context.isDocument());

    auto worker = adoptRef(*new Worker(context, runtimeFlags));

    worker->suspendIfNeeded();

    bool shouldBypassMainWorldContentSecurityPolicy = context.shouldBypassMainWorldContentSecurityPolicy();
    auto scriptURL = worker->resolveURL(url, shouldBypassMainWorldContentSecurityPolicy);
    if (scriptURL.hasException())
        return scriptURL.releaseException();

    worker->m_shouldBypassMainWorldContentSecurityPolicy = shouldBypassMainWorldContentSecurityPolicy;

    // The worker context does not exist while loading, so we must ensure that the worker object is not collected, nor are its event listeners.
    worker->setPendingActivity(worker.ptr());

    worker->m_scriptLoader = WorkerScriptLoader::create();
    auto contentSecurityPolicyEnforcement = shouldBypassMainWorldContentSecurityPolicy ? ContentSecurityPolicyEnforcement::DoNotEnforce : ContentSecurityPolicyEnforcement::EnforceChildSrcDirective;
    worker->m_scriptLoader->loadAsynchronously(&context, scriptURL.releaseReturnValue(), FetchOptions::Mode::SameOrigin, contentSecurityPolicyEnforcement, worker->m_identifier, worker.ptr());
    return WTFMove(worker);
}
Exemple #5
0
bool RequestURI::process(const VirtualHost *vhost, Transport *transport,
                         const string &sourceRoot,
                         const string &pathTranslation, const char *url) {
  splitURL(url, m_originalURL, m_queryString);
  m_originalURL = StringUtil::UrlDecode(m_originalURL, false);
  m_rewritten = false;

  // Fast path for files that exist unless VirtualHost option StaticFastPath is false, in
  // which case rewrite rules are applied even if the original path points to an existing static file.

  String canon(Util::canonicalize(m_originalURL.c_str(), m_originalURL.size()),
               AttachString);


  if ( vhost->staticfastpath() )
    {
    if (virtualFileExists(vhost, sourceRoot, pathTranslation, canon)) {
      m_rewrittenURL = canon;
      m_resolvedURL = canon;
      return true;
    }
  }


  if (!rewriteURL(vhost, transport, pathTranslation, sourceRoot)) {
    // Redirection
    m_done = true;
    return true;
  }
  if (!resolveURL(vhost, pathTranslation, sourceRoot)) {
    // Can't find
    return false;
  }
  return true;
}
SharedWorker::SharedWorker(const String& url, const String& name, ScriptExecutionContext* context, ExceptionCode& ec)
    : AbstractWorker(context)
{
    RefPtr<MessageChannel> channel = MessageChannel::create(scriptExecutionContext());
    m_port = channel->port1();
    OwnPtr<MessagePortChannel> remotePort = channel->port2()->disentangle(ec);
    ASSERT(!ec);

    KURL scriptUrl = resolveURL(url, ec);
    if (ec)
        return;
    SharedWorkerRepository::connect(this, remotePort.release(), scriptUrl, name, ec);
}
bool InProcessWorkerBase::initialize(ExecutionContext* context, const String& url, ExceptionState& exceptionState)
{
    suspendIfNeeded();

    KURL scriptURL = resolveURL(url, exceptionState);
    if (scriptURL.isEmpty())
        return false;

    m_scriptLoader = WorkerScriptLoader::create();
    m_scriptLoader->loadAsynchronously(*context, scriptURL, DenyCrossOriginRequests, this);

    m_contextProxy = createWorkerGlobalScopeProxy(context);

    return true;
}
Exemple #8
0
Worker::Worker(const String& url, ScriptExecutionContext* context, ExceptionCode& ec)
    : AbstractWorker(context)
    , m_contextProxy(WorkerContextProxy::create(this))
{
    KURL scriptURL = resolveURL(url, ec);
    if (ec)
        return;

    m_scriptLoader = new WorkerScriptLoader(ResourceRequestBase::TargetIsWorker);
    m_scriptLoader->loadAsynchronously(scriptExecutionContext(), scriptURL, DenyCrossOriginRequests, this);
    setPendingActivity(this);  // The worker context does not exist while loading, so we must ensure that the worker object is not collected, as well as its event listeners.
#if ENABLE(INSPECTOR)
    if (InspectorController* inspector = scriptExecutionContext()->inspectorController())
        inspector->didCreateWorker(asID(), scriptURL.string(), false);
#endif
}
Exemple #9
0
bool RequestURI::process(const VirtualHost *vhost, Transport *transport,
                         const std::string &sourceRoot,
                         const std::string &pathTranslation, const char *url) {
  splitURL(url, m_originalURL, m_queryString);
  m_originalURL = StringUtil::UrlDecode(m_originalURL, false);
  m_rewritten = false;

  auto pathTranslated = transport->getPathTranslated();
  if (!pathTranslated.empty()) {
    // The transport is overriding everything and just handing us the filename
    m_path = m_absolutePath = pathTranslated;
    processExt();
    return true;
  }

  // Fast path for files that exist
  if (vhost->checkExistenceBeforeRewrite()) {
    String canon(
      Util::canonicalize(m_originalURL.c_str(), m_originalURL.size()),
      AttachString);
    if (virtualFileExists(vhost, sourceRoot, pathTranslation, canon)) {
      m_rewrittenURL = canon;
      m_resolvedURL = canon;
      return true;
    }
  }

  if (!rewriteURL(vhost, transport, pathTranslation, sourceRoot)) {
    // Redirection
    m_done = true;
    return true;
  }
  if (!resolveURL(vhost, pathTranslation, sourceRoot)) {
    // Can't find
    return false;
  }
  return true;
}
Exemple #10
0
static void processHTTPGetRequest(int hSocket, char inBuffer[], char* url)
{
	int result;
	struct stat filestat;
	char* resource = (char*) malloc (strlen(ml_server_getRootDir()) + strlen(url) + 10);
	memset(resource, '\0', sizeof(resource));

	// check for absolute url format
	if (url[0] != '/')
	{
		respondAlert(hSocket, 400, "Please supply an absolute url");
		free(resource);
		return;
	}

	// we don't handle dynamic url's
	if (strchr(url, '?') != NULL)
	{
		respondAlert(hSocket, 501, "Server only serves static resources");
		free(resource);
		return;
	}

	// resolve the url if possible to a file location
	result = resolveURL(url, resource);
	if (result != SUCCESS)
	{
		respondAlert(hSocket, 400, "Bad request");
		free(resource);
		return;
	}

	// is path legally located ? else send (Forbidden)
	if (strncmp(resource, ml_server_getRootDir(), strlen(ml_server_getRootDir())))
	{
		respondAlert(hSocket, 403, "Requested file outside root server directory");
		free(resource);
		return;
	}

	// is path exist ? else send (Not Found)
	if (stat(resource, &filestat) < 0)
	{
		respondAlert(hSocket, 404, "Unable to locate this file");
		free(resource);
		return;
	}

	// alright baby let's return this sucker!
	if (S_ISDIR(filestat.st_mode))
	{
		respondDirectory(hSocket, resource);
	}
	else if (S_ISREG(filestat.st_mode))
	{
		respondRegularFile(hSocket, resource, filestat.st_size);
	}
	else
	{
		respondAlert(hSocket, 403, "Invalid file mode");
	}

	free(resource);
}