OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to make ASP .NET Run in Node JS, or hide javascript if it is not possible

  • Thread starter Thread starter Arthur Yoshikasu Arakaki
  • Start date Start date
A

Arthur Yoshikasu Arakaki

Guest
I want to make a login but the problem is that using js the code gets visible, making it insecure

I use this code to run my login run the Local Webserver

Code:
/*
 *   Copyright (c) 2024 DEMnetwork
 *   All rights reserved.

 *   Permission is hereby granted, free of charge, to any person obtaining a copy
 *   of this software and associated documentation files (the "Software"), to deal
 *   in the Software without restriction, including without limitation the rights
 *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *   copies of the Software, and to permit persons to whom the Software is
 *   furnished to do so, subject to the following conditions:
 
 *   The above copyright notice and this permission notice shall be included in all
 *   copies or substantial portions of the Software.
 
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 *   SOFTWARE.
 */
var http = require('http');
var url = require('url');
var fs = require('fs');
const dashboard_data = {home: "<head><title>Dashboard | Home</title></head><body><h1>Dashboard</h1><p>Welcome to the dashboard</p></body>", logout: "<head><title>Dashboard | Logout</title></head><body onload=\"logout()\"><script>function logout() {window.location.replace(\"http://192.168.0.14:8529/dashboard/\")}</script></body>"}
var csid = [Math.floor(Math.random() * 2147483647), Math.floor(Math.random() * 2147483647), Math.floor(Math.random() * 2147483647), Math.floor(Math.random() * 2147483647)]
http.createServer(function (req, res) {
    var q = url.parse(req.url, true);
    var filename = "." + q.pathname;
    var path = q.pathname
    if (filename === "./") {
      fs.readFile('index.html', function(err, data) {
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.write(data);
        console.log("filename: " + filename);
        console.log("q: " + q);
        return res.end();
      });
    }
    else {
      if (filename == "./dashboard/" && q.search == "?csid=" + csid[0] + "-" + csid[1] + "-" + csid[2] + "-" + csid[3] + "&location=home") {
        res.writeHead(200, {'Content-Type': 'text/html'});
        console.log("filename: " + filename);
        console.log("Port: " + q.port)
        console.log("Hostname: " + q.hostname)
        console.log("Host: " + q.host)
        console.log("Search: " + q.search)
        console.log("q: " + q);
        res.write(dashboard_data.home);
        return res.end();
      } 
      else {
        if (filename == "./dashboard/js/loginmgr.js") {
          fs.readFile(filename, function(err, data) {
            res.writeHead(200, {'Content-Type': 'text/javascript'});
            res.write("const csid =[" + csid[0] + ", " + csid[1] + ", " + csid[2] + ", " + csid[3] + "] \n" + data);
            console.log("filename: " + filename);
            console.log("Port: " + q.port)
            console.log("Hostname: " + q.hostname)
            console.log("Host: " + q.host)
            console.log("Search: " + q.search)
            console.log("q: " + q);
            return res.end();
          })
        }
        else {
          if (filename == "./dashboard/" && q.search == "?csid=" + csid[0] + "-" + csid[1] + "-" + csid[2] + "-" + csid[3] + "&location=logout") {
            res.writeHead(200, {'Content-Type': 'text/html'});
            console.log("filename: " + filename);
            console.log("Port: " + q.port)
            console.log("Hostname: " + q.hostname)
            console.log("Host: " + q.host)
            console.log("Search: " + q.search)
            console.log("q: " + q);
            csid = [Math.floor(Math.random() * 2147483647), Math.floor(Math.random() * 2147483647), Math.floor(Math.random() * 2147483647), Math.floor(Math.random() * 2147483647)]
            res.write(dashboard_data.logout);
            return res.end();
          }
          else { 
      fs.readFile(filename + ".html", function(err, data) {
        if (err) {
            if (filename.endsWith(".js") == true) {
              fs.readFile(filename, function(err, data) {
                if (err) {
                  res.writeHead(404, {'Content-Type': 'text/html'});
                  console.log("filename: " + filename);
                  console.log("q: " + q);
                  return res.end("<h1>HTTP ERROR</h1><p></p><strong>404 Not Found</strong><p></p><p>The requested page: \'" + path + ".js\' was not found</p>");
                }
                res.writeHead(200, {'Content-Type': 'text/javascript'});
                res.write(data);
                console.log("filename: " + filename);
                console.log("Port: " + q.port)
                console.log("Hostname: " + q.hostname)
                console.log("Host: " + q.host)
                console.log("Search: " + q.search)
                console.log("q: " + q);
                return res.end();
              });
            }
            else {
              if (filename.endsWith(".css") == true) {
                fs.readFile(filename, function(err, data) {
                  if (err) {
                    res.writeHead(404, {'Content-Type': 'text/html'});
                    console.log("filename: " + filename);
                    console.log("q: " + q);
                    return res.end("<h1>HTTP ERROR</h1><p></p><strong>404 Not Found</strong><p></p><p>The requested page: \'" + path + ".css\' was not found</p>");
                  }
                  res.writeHead(200, {'Content-Type': 'text/css'});
                  res.write(data);
                  console.log("filename: " + filename);
                  console.log("Port: " + q.port)
                  console.log("Hostname: " + q.hostname)
                  console.log("Host: " + q.host)
                  console.log("Search: " + q.search)
                  console.log("q: " + q);
                return res.end();
                    });
                }
                else {
                  if (filename.endsWith(".png") == true) {
                    fs.readFile(filename, function(err, data) {
                      if (err) {
                        res.writeHead(404, {'Content-Type': 'text/html'});
                        console.log("filename: " + filename);
                        console.log("q: " + q);
                        return res.end("<h1>HTTP ERROR</h1><p></p><strong>404 Not Found</strong><p></p><p>The requested page: \'" + path + ".png\' was not found</p>");
                      }
                      res.writeHead(200, {'Content-Type': 'image/png'});
                      res.write(data);
                      console.log("filename: " + filename);
                      console.log("Port: " + q.port)
                      console.log("Hostname: " + q.hostname)
                      console.log("Host: " + q.host)
                      console.log("Search: " + q.search)
                      console.log("q: " + q);
                      return res.end();
                    })
                  }
                  else {
                    if (filename.endsWith(".ico") == true){
                      fs.readFile(filename, function(err, data) {
                        if (err) {
                          res.writeHead(404, {'Content-Type': 'text/html'});
                          console.log("filename: " + filename);
                          console.log("q: " + q);
                          return res.end("<h1>HTTP ERROR</h1><p></p><strong>404 Not Found</strong><p></p><p>The requested page: \'" + path + ".ico\' was not found</p>");
                        }
                        res.writeHead(200, {'Content-Type': 'image/*'});
                        res.write(data);
                        console.log("filename: " + filename);
                        console.log("Port: " + q.port)
                        console.log("Hostname: " + q.hostname)
                        console.log("Host: " + q.host)
                        console.log("Search: " + q.search)
                        console.log("q: " + q);
                        return res.end();
                      })
                    }
                    else {
                res.writeHead(404, {'Content-Type': 'text/html'});
                console.log("filename: " + filename);
                console.log("q: " + q);
                return res.end("<h1>HTTP ERROR</h1><p></p><strong>404 Not Found</strong><p></p><p>The requested page: \'" + path + ".html\' was not found</p>");
                }
              }
               }
              }
          }
        else {
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.write(data);
        console.log("filename: " + filename);
        console.log("Port: " + q.port)
        console.log("Hostname: " + q.hostname)
        console.log("Host: " + q.host)
        console.log("Search: " + q.search)
        console.log("q: " + q);
      return res.end();
      }
    });
  }
  }
  }
}
}).listen(8529);

The problem is even if a allow the .cshtml files to get displayed it shows it as plain text(Only the HTML is shown and the CODE it shown as plain text(It doesn't get executed))

<p>I want to make a login but the problem is that using js the code gets visible, making it insecure</p>
<p>I use this code to run my login run the Local Webserver</p>
<pre class="lang-js prettyprint-override"><code>/*
* Copyright (c) 2024 DEMnetwork
* All rights reserved.

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:

* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
var http = require('http');
var url = require('url');
var fs = require('fs');
const dashboard_data = {home: "<head><title>Dashboard | Home</title></head><body><h1>Dashboard</h1><p>Welcome to the dashboard</p></body>", logout: "<head><title>Dashboard | Logout</title></head><body onload=\"logout()\"><script>function logout() {window.location.replace(\"http://192.168.0.14:8529/dashboard/\")}</script></body>"}
var csid = [Math.floor(Math.random() * 2147483647), Math.floor(Math.random() * 2147483647), Math.floor(Math.random() * 2147483647), Math.floor(Math.random() * 2147483647)]
http.createServer(function (req, res) {
var q = url.parse(req.url, true);
var filename = "." + q.pathname;
var path = q.pathname
if (filename === "./") {
fs.readFile('index.html', function(err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
console.log("filename: " + filename);
console.log("q: " + q);
return res.end();
});
}
else {
if (filename == "./dashboard/" && q.search == "?csid=" + csid[0] + "-" + csid[1] + "-" + csid[2] + "-" + csid[3] + "&location=home") {
res.writeHead(200, {'Content-Type': 'text/html'});
console.log("filename: " + filename);
console.log("Port: " + q.port)
console.log("Hostname: " + q.hostname)
console.log("Host: " + q.host)
console.log("Search: " + q.search)
console.log("q: " + q);
res.write(dashboard_data.home);
return res.end();
}
else {
if (filename == "./dashboard/js/loginmgr.js") {
fs.readFile(filename, function(err, data) {
res.writeHead(200, {'Content-Type': 'text/javascript'});
res.write("const csid =[" + csid[0] + ", " + csid[1] + ", " + csid[2] + ", " + csid[3] + "] \n" + data);
console.log("filename: " + filename);
console.log("Port: " + q.port)
console.log("Hostname: " + q.hostname)
console.log("Host: " + q.host)
console.log("Search: " + q.search)
console.log("q: " + q);
return res.end();
})
}
else {
if (filename == "./dashboard/" && q.search == "?csid=" + csid[0] + "-" + csid[1] + "-" + csid[2] + "-" + csid[3] + "&location=logout") {
res.writeHead(200, {'Content-Type': 'text/html'});
console.log("filename: " + filename);
console.log("Port: " + q.port)
console.log("Hostname: " + q.hostname)
console.log("Host: " + q.host)
console.log("Search: " + q.search)
console.log("q: " + q);
csid = [Math.floor(Math.random() * 2147483647), Math.floor(Math.random() * 2147483647), Math.floor(Math.random() * 2147483647), Math.floor(Math.random() * 2147483647)]
res.write(dashboard_data.logout);
return res.end();
}
else {
fs.readFile(filename + ".html", function(err, data) {
if (err) {
if (filename.endsWith(".js") == true) {
fs.readFile(filename, function(err, data) {
if (err) {
res.writeHead(404, {'Content-Type': 'text/html'});
console.log("filename: " + filename);
console.log("q: " + q);
return res.end("<h1>HTTP ERROR</h1><p></p><strong>404 Not Found</strong><p></p><p>The requested page: \'" + path + ".js\' was not found</p>");
}
res.writeHead(200, {'Content-Type': 'text/javascript'});
res.write(data);
console.log("filename: " + filename);
console.log("Port: " + q.port)
console.log("Hostname: " + q.hostname)
console.log("Host: " + q.host)
console.log("Search: " + q.search)
console.log("q: " + q);
return res.end();
});
}
else {
if (filename.endsWith(".css") == true) {
fs.readFile(filename, function(err, data) {
if (err) {
res.writeHead(404, {'Content-Type': 'text/html'});
console.log("filename: " + filename);
console.log("q: " + q);
return res.end("<h1>HTTP ERROR</h1><p></p><strong>404 Not Found</strong><p></p><p>The requested page: \'" + path + ".css\' was not found</p>");
}
res.writeHead(200, {'Content-Type': 'text/css'});
res.write(data);
console.log("filename: " + filename);
console.log("Port: " + q.port)
console.log("Hostname: " + q.hostname)
console.log("Host: " + q.host)
console.log("Search: " + q.search)
console.log("q: " + q);
return res.end();
});
}
else {
if (filename.endsWith(".png") == true) {
fs.readFile(filename, function(err, data) {
if (err) {
res.writeHead(404, {'Content-Type': 'text/html'});
console.log("filename: " + filename);
console.log("q: " + q);
return res.end("<h1>HTTP ERROR</h1><p></p><strong>404 Not Found</strong><p></p><p>The requested page: \'" + path + ".png\' was not found</p>");
}
res.writeHead(200, {'Content-Type': 'image/png'});
res.write(data);
console.log("filename: " + filename);
console.log("Port: " + q.port)
console.log("Hostname: " + q.hostname)
console.log("Host: " + q.host)
console.log("Search: " + q.search)
console.log("q: " + q);
return res.end();
})
}
else {
if (filename.endsWith(".ico") == true){
fs.readFile(filename, function(err, data) {
if (err) {
res.writeHead(404, {'Content-Type': 'text/html'});
console.log("filename: " + filename);
console.log("q: " + q);
return res.end("<h1>HTTP ERROR</h1><p></p><strong>404 Not Found</strong><p></p><p>The requested page: \'" + path + ".ico\' was not found</p>");
}
res.writeHead(200, {'Content-Type': 'image/*'});
res.write(data);
console.log("filename: " + filename);
console.log("Port: " + q.port)
console.log("Hostname: " + q.hostname)
console.log("Host: " + q.host)
console.log("Search: " + q.search)
console.log("q: " + q);
return res.end();
})
}
else {
res.writeHead(404, {'Content-Type': 'text/html'});
console.log("filename: " + filename);
console.log("q: " + q);
return res.end("<h1>HTTP ERROR</h1><p></p><strong>404 Not Found</strong><p></p><p>The requested page: \'" + path + ".html\' was not found</p>");
}
}
}
}
}
else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
console.log("filename: " + filename);
console.log("Port: " + q.port)
console.log("Hostname: " + q.hostname)
console.log("Host: " + q.host)
console.log("Search: " + q.search)
console.log("q: " + q);
return res.end();
}
});
}
}
}
}
}).listen(8529);
</code></pre>
<p>The problem is even if a allow the <code>.cshtml</code> files to get displayed it shows it as plain text(Only the HTML is shown and the CODE it shown as plain text(It doesn't get executed))</p>
 

Latest posts

H
Replies
0
Views
1
Hür Doğan ÜNLÜ
H
Top