Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Wrong redirect when running behind nginx #1053

Open
tosiara opened this issue Mar 25, 2024 · 4 comments
Open

[BUG]: Wrong redirect when running behind nginx #1053

tosiara opened this issue Mar 25, 2024 · 4 comments
Labels
bug Something isn't working server Hashtopolis API/Server related

Comments

@tosiara
Copy link

tosiara commented Mar 25, 2024

Version Information

0.14.2

Hashcat

No response

Description

I have exposed hashtopolis to outside network through an nginx:

location /newhashtopolis
        {
		rewrite /newhashtopolis/(.*) /$1  break;
		proxy_redirect     off;
		proxy_set_header   Host $host;
                proxy_pass http://192.168.0.13:8080;
        }

In the settings I specified that prefix:

image

I'm able to login and navigate to Tasks.
But when I try to enable/disable an agent, the redirect is done to /agent.php:

Server: nginx/1.25.4
Date: Mon, 25 Mar 2024 16:17:44 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 0
Connection: keep-alive
X-Powered-By: PHP/8.3.4
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: session=xxx; expires=Mon, 25 Mar 2024 17:17:44 GMT; Max-Age=3600; HttpOnly
Location: /agents.php

Which results in 404 error.

No matter what I put into "base path", it always redirects to /agents.php

@tosiara tosiara added the bug Something isn't working label Mar 25, 2024
@tosiara
Copy link
Author

tosiara commented Mar 25, 2024

This function may be the root cause, it performs redirect without taking into account the base:
https://github.com/hashtopolis/server/blob/master/src/inc/Util.class.php#L701

@tosiara
Copy link
Author

tosiara commented Mar 25, 2024

This fixed my issue:

diff --git a/src/inc/Util.class.php b/src/inc/Util.class.php
index e64073a9..66a4fa4e 100755
--- a/src/inc/Util.class.php
+++ b/src/inc/Util.class.php
@@ -701,7 +701,7 @@ class Util {
   public static function refresh() {
     global $_SERVER;

-    $url = $_SERVER['PHP_SELF'];
+    $url = SConfig::getInstance()->getVal(DConfig::BASE_URL) . $_SERVER['PHP_SELF'];
     if (strlen($_SERVER['QUERY_STRING']) > 0) {
       $url .= "?" . $_SERVER['QUERY_STRING'];
     }

@tosiara
Copy link
Author

tosiara commented Mar 26, 2024

Found more places where redirect does not honor the base prefix:
https://github.com/search?q=repo%3Ahashtopolis%2Fserver%20%26fw%3D&type=code

@zyronix
Copy link
Member

zyronix commented Mar 27, 2024

Thanks for your bug reports and this detailed one!

@zyronix zyronix added the server Hashtopolis API/Server related label Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server Hashtopolis API/Server related
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants