diff --git a/app/app.php b/app/app.php index cd881fab1c..721fe15d75 100644 --- a/app/app.php +++ b/app/app.php @@ -42,7 +42,7 @@ $clients = array_map(function($node) { })); $utopia->init(function() use ($utopia, $request, $response, $register, &$user, $project, $roles, $webhook, $audit, $usage, $domain, $clients) { - + $route = $utopia->match($request); /** @@ -51,8 +51,8 @@ $utopia->init(function() use ($utopia, $request, $response, $register, &$user, $ $https = $request->getServer('HTTP_X_FORWARDED_PROTO', $request->getServer('HTTPS', '')); if (empty($https) || 'off' == $https) { - $response->redirect('https://' . $request->getServer('HTTP_HOST', '') . $request->getServer('REQUEST_URI')); - exit(0); + //$response->redirect('https://' . $request->getServer('HTTP_HOST', '') . $request->getServer('REQUEST_URI')); + //exit(0); } $referrer = $request->getServer('HTTP_REFERER', ''); @@ -70,11 +70,11 @@ $utopia->init(function() use ($utopia, $request, $response, $register, &$user, $ $response ->addHeader('Server', 'Appwrite') ->addHeader('X-XSS-Protection', '1; mode=block; report=/v1/xss?url=' . urlencode($request->getServer('REQUEST_URI'))) - ->addHeader('Strict-Transport-Security', 'max-age=16070400') + //->addHeader('Strict-Transport-Security', 'max-age=16070400') //->addHeader('X-Frame-Options', ($refDomain == 'http://localhost') ? 'SAMEORIGIN' : 'ALLOW-FROM ' . $refDomain) ->addHeader('X-Content-Type-Options', 'nosniff') ->addHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE') - ->addHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Access-Control-Request-Headers, Ajax, Origin, Content-Type, Accept, X-Appwrite-Project, X-Appwrite-Key, X-Appwrite-Locale, X-SDK-Version') + ->addHeader('Access-Control-Allow-Headers', 'Origin, Cookie, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Access-Control-Request-Headers, Accept, X-Appwrite-Project, X-Appwrite-Key, X-Appwrite-Locale, X-SDK-Version') ->addHeader('Access-Control-Allow-Origin', $refDomain) ->addHeader('Access-Control-Allow-Credentials', 'true') ; @@ -83,7 +83,7 @@ $utopia->init(function() use ($utopia, $request, $response, $register, &$user, $ * Validate Client Domain - Check to avoid CSRF attack * Adding appwrite api domains to allow XDOMAIN communication */ - $hostValidator = new Host(array_merge($clients, ['http://localhost', 'https://localhost', 'https://appwrite.test', 'https://appwrite.io'])); + $hostValidator = new Host($clients); if(!$hostValidator->isValid($request->getServer('HTTP_ORIGIN', $request->getServer('HTTP_REFERER', ''))) && in_array($request->getMethod(), [Request::METHOD_POST, Request::METHOD_PUT, Request::METHOD_PATCH, Request::METHOD_DELETE]) @@ -249,7 +249,7 @@ $utopia->options(function() use ($request, $response, $domain, $project) { $response ->addHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE') - ->addHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Access-Control-Request-Headers, Ajax, Origin, Content-Type, Accept, X-Appwrite-Project, X-Appwrite-Key, X-Appwrite-Locale, X-SDK-Version') + ->addHeader('Access-Control-Allow-Headers', 'Origin, Cookie, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Access-Control-Request-Headers, Accept, X-Appwrite-Project, X-Appwrite-Key, X-Appwrite-Locale, X-SDK-Version') ->addHeader('Access-Control-Allow-Origin', $origin) ->addHeader('Access-Control-Allow-Credentials', 'true') ->send(); @@ -462,7 +462,7 @@ $utopia->get('/v1/open-api-2.json') ->label('docs', false) ->param('extensions', 0 , function () {return new Range(0, 1);}, 'Show extra data.', true) ->action( - function($extensions) use ($response, $utopia, $domain, $version, $services, $consoleDB) { + function($extensions) use ($response, $request, $utopia, $domain, $version, $services) { function fromCamelCase($input) { preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches); @@ -613,7 +613,7 @@ $utopia->get('/v1/open-api-2.json') ), 'externalDocs' => [ 'description' => 'Full API docs, specs and tutorials', - 'url' => APP_PROTOCOL . '://' . $domain . '/docs' + 'url' => $request->getServer('REQUEST_SCHEME', 'https') . '://' . $domain . '/docs' ] ]; diff --git a/app/controllers/account.php b/app/controllers/account.php index a70fbd34ab..841dbe0cc9 100644 --- a/app/controllers/account.php +++ b/app/controllers/account.php @@ -338,7 +338,7 @@ $utopia->delete('/v1/account') ->label('sdk.method', 'delete') ->label('sdk.description', 'Delete currently logged in user account.') ->action( - function() use ($response, $user, $projectDB, $audit) + function() use ($response, $request, $user, $projectDB, $audit) { $user = $projectDB->updateDocument(array_merge($user->getArrayCopy(), [ 'status' => Auth::USER_STATUS_BLOCKED, @@ -367,7 +367,7 @@ $utopia->delete('/v1/account') ; $response - ->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == APP_PROTOCOL), true) + ->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true) ->json(array('result' => 'success')); } ); \ No newline at end of file diff --git a/app/controllers/auth.php b/app/controllers/auth.php index 0f26a2d969..dd1ad54804 100644 --- a/app/controllers/auth.php +++ b/app/controllers/auth.php @@ -167,7 +167,7 @@ $utopia->post('/v1/auth/register') ->setParam('event', 'auth.register') ; - $response->addCookie(Auth::$cookieName, Auth::encodeSession($user->getUid(), $loginSecret), $expiry, '/', COOKIE_DOMAIN, ('https' == APP_PROTOCOL), true); + $response->addCookie(Auth::$cookieName, Auth::encodeSession($user->getUid(), $loginSecret), $expiry, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true); if($success) { $response->redirect($success); @@ -369,7 +369,7 @@ $utopia->post('/v1/auth/login') ; $response - ->addCookie(Auth::$cookieName, Auth::encodeSession($profile->getUid(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == APP_PROTOCOL), true); + ->addCookie(Auth::$cookieName, Auth::encodeSession($profile->getUid(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true); if($success) { $response->redirect($success); @@ -408,7 +408,7 @@ $utopia->delete('/v1/auth/logout') $audit->setParam('event', 'auth.logout'); $response - ->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == APP_PROTOCOL), true) + ->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true) ->json(array('result' => 'success')) ; } @@ -440,7 +440,7 @@ $utopia->delete('/v1/auth/logout/:id') ; if($token->getAttribute('secret') == Auth::hash(Auth::$secret)) { // If current session delete cookies - $response->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == APP_PROTOCOL), true); + $response->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true); } } } @@ -608,7 +608,7 @@ $utopia->get('/v1/oauth/:provider') ->action( function($provider, $success, $failure) use ($response, $request, $project) { - $callback = APP_PROTOCOL . '://' . $request->getServer('HTTP_HOST') . '/v1/oauth/callback/' . $provider . '/' . $project->getUid(); + $callback = $request->getServer('REQUEST_SCHEME', 'https') . '://' . $request->getServer('HTTP_HOST') . '/v1/oauth/callback/' . $provider . '/' . $project->getUid(); $appId = $project->getAttribute('usersOauth' . ucfirst($provider) . 'Appid', ''); $appSecret = $project->getAttribute('usersOauth' . ucfirst($provider) . 'Secret', '{}'); @@ -672,9 +672,9 @@ $utopia->get('/v1/oauth/callback/:provider/:projectId') ->param('code', '', function () {return new Text(1024);}, 'OAuth code') ->param('state', '', function () {return new Text(2048);}, 'Login state params', true) ->action( - function($projectId, $provider, $code, $state) use ($response, $domain) + function($projectId, $provider, $code, $state) use ($response, $request, $domain) { - $response->redirect(APP_PROTOCOL . '://' . $domain . '/v1/oauth/' . $provider . '/redirect?' + $response->redirect($request->getServer('REQUEST_SCHEME', 'https') . '://' . $domain . '/v1/oauth/' . $provider . '/redirect?' . http_build_query(['project' => $projectId, 'code' => $code, 'state' => $state])); } ); @@ -695,7 +695,7 @@ $utopia->get('/v1/oauth/:provider/redirect') ->action( function($provider, $code, $state) use ($response, $request, $user, $projectDB, $project, $audit) { - $callback = APP_PROTOCOL . '://' . $request->getServer('HTTP_HOST') . '/v1/oauth/callback/' . $provider . '/' . $project->getUid(); + $callback = $request->getServer('REQUEST_SCHEME', 'https') . '://' . $request->getServer('HTTP_HOST') . '/v1/oauth/callback/' . $provider . '/' . $project->getUid(); $defaultState = ['success' => $project->getAttribute('url', ''), 'failure' => '']; $validateURL = new URL(); @@ -868,7 +868,7 @@ $utopia->get('/v1/oauth/:provider/redirect') ; $response - ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getUid(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == APP_PROTOCOL), true) + ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getUid(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true) ; $response->redirect($state['success']); diff --git a/app/controllers/console.php b/app/controllers/console.php index dfa5c85fd5..2a0c1d7749 100644 --- a/app/controllers/console.php +++ b/app/controllers/console.php @@ -18,6 +18,10 @@ $utopia->shutdown(function() use ($utopia, $response, $request, $layout, $versio $header = new View(__DIR__ . '/../views/console/comps/header.phtml'); $footer = new View(__DIR__ . '/../views/console/comps/footer.phtml'); + $footer + ->setParam('home', $request->getServer('_APP_HOME', '')) + ; + $layout ->setParam('header', [$header]) ->setParam('footer', [$footer]) @@ -54,10 +58,14 @@ $utopia->get('/error/:code') $utopia->get('/console') ->label('permission', 'public') ->label('scope', 'console') - ->action(function() use ($layout) + ->action(function() use ($layout, $request) { $page = new View(__DIR__ . '/../views/console/index.phtml'); + $page + ->setParam('home', $request->getServer('_APP_HOME', '')) + ; + $layout ->setParam('title', APP_NAME . ' - ' . Locale::getText('console.title')) ->setParam('body', $page); diff --git a/app/controllers/shared/web.php b/app/controllers/shared/web.php index e3e803e10e..035177a702 100644 --- a/app/controllers/shared/web.php +++ b/app/controllers/shared/web.php @@ -21,6 +21,7 @@ if(!empty($request->getQuery('version', ''))) { $layout ->setParam('title', APP_NAME) ->setParam('description', Locale::getText('general.description')) + ->setParam('protocol', $request->getServer('REQUEST_SCHEME', 'https')) ->setParam('domain', $domain) ->setParam('api', $request->getServer('_APP_APPWRITE_HOST_CLIENT')) ->setParam('project', $request->getServer('_APP_APPWRITE_ID')) diff --git a/app/controllers/teams.php b/app/controllers/teams.php index 81215f8a04..c98c6e1541 100644 --- a/app/controllers/teams.php +++ b/app/controllers/teams.php @@ -598,7 +598,7 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status') ->setParam('event', 'auth.join') ; - $response->addCookie(Auth::$cookieName, Auth::encodeSession($user->getUid(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == APP_PROTOCOL), true); + $response->addCookie(Auth::$cookieName, Auth::encodeSession($user->getUid(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true); if($success) { $response->redirect($success); diff --git a/app/init.php b/app/init.php index 84af8eeeb1..a171124b8e 100644 --- a/app/init.php +++ b/app/init.php @@ -18,7 +18,6 @@ use Utopia\Locale\Locale; use Utopia\Registry\Registry; use PHPMailer\PHPMailer\PHPMailer; -const APP_PROTOCOL = 'https'; const APP_NAME = 'Appwrite'; const APP_DOMAIN = 'appwrite.io'; const APP_EMAIL_TEAM = 'team@' . APP_DOMAIN; diff --git a/app/views/console/settings/index.phtml b/app/views/console/settings/index.phtml index 2ea7b4a7e6..7bc666921a 100644 --- a/app/views/console/settings/index.phtml +++ b/app/views/console/settings/index.phtml @@ -168,7 +168,7 @@ use Utopia\Locale\Locale; - + @@ -202,7 +202,7 @@ use Utopia\Locale\Locale; data-failure-param-alert-classname="error"> - + diff --git a/app/views/console/users/index.phtml b/app/views/console/users/index.phtml index 756534a51f..59eba27554 100644 --- a/app/views/console/users/index.phtml +++ b/app/views/console/users/index.phtml @@ -344,7 +344,7 @@ $providers = $this->getParam('providers', []);

To complete set up, add this OAuth redirect URI to your app configuration.

- +
diff --git a/app/views/home/auth/join.phtml b/app/views/home/auth/join.phtml index 65a8a6380f..9b6bc01c96 100644 --- a/app/views/home/auth/join.phtml +++ b/app/views/home/auth/join.phtml @@ -19,8 +19,8 @@ use Utopia\Locale\Locale; - - + +
escape(Locale::getText('home.auth.recovery.labels.email')); ?> - + diff --git a/app/views/home/auth/signin.phtml b/app/views/home/auth/signin.phtml index a9d01c8f84..eaa72f65ec 100644 --- a/app/views/home/auth/signin.phtml +++ b/app/views/home/auth/signin.phtml @@ -14,9 +14,9 @@ use Utopia\Locale\Locale;

escape(Locale::getText('home.auth.signin.oauth.title')); ?>

- - Connect with Github - Connect with Linkedin + + Connect with Github + Connect with Linkedin
@@ -34,8 +34,8 @@ use Utopia\Locale\Locale; data-failure-param-alert-text="escape(Locale::getText('home.auth.signin.failure')); ?>" data-failure-param-alert-classname="error"> - - + + diff --git a/app/views/home/auth/signup.phtml b/app/views/home/auth/signup.phtml index 7195cff0a3..e31f80244c 100644 --- a/app/views/home/auth/signup.phtml +++ b/app/views/home/auth/signup.phtml @@ -24,8 +24,8 @@ use Utopia\Locale\Locale; data-failure-param-alert-text="escape(Locale::getText('home.auth.signup.failure')); ?>" data-failure-param-alert-classname="error"> - - + + @@ -43,7 +43,7 @@ use Utopia\Locale\Locale; escape(Locale::getText('home.auth.signup.labels.agree')); ?>escape(Locale::getText('home.auth.signup.labels.terms')); ?>escape(Locale::getText('home.auth.signup.labels.and')); ?>escape(Locale::getText('home.auth.signup.labels.privacy')); ?> - + @@ -52,9 +52,9 @@ use Utopia\Locale\Locale;

escape(Locale::getText('home.auth.signin.oauth.title')); ?>

- Connect with Facebook - Connect with Github - Connect with Linkedin + Connect with Facebook + Connect with Github + Connect with Linkedin
diff --git a/app/views/layouts/default.phtml b/app/views/layouts/default.phtml index 92be315cd7..2a21f9d5c8 100644 --- a/app/views/layouts/default.phtml +++ b/app/views/layouts/default.phtml @@ -2,6 +2,7 @@ use Utopia\Locale\Locale; +$protocol = $this->getParam('protocol', ''); $domain = $this->getParam('domain', ''); $api = $this->getParam('api', ''); $project = $this->getParam('project', ''); @@ -33,7 +34,7 @@ $env = $this->getParam('env', ''); - +