Solved

Serverside Javascript

Posted on 2012-03-28
13
199 Views
Last Modified: 2012-10-19
I've been working with javascript for a long time now and one thing I'd always disliked is the inability to be able to hide the code so you can protect your intellectual property when deploying scripts to a customer. The application framework I work within uses serverside javascript as it's scripting language. The framework is a web based application. When certain events occur in the framework such as a record update, insert or delete, I can add additional code into these steps to make other things happen similar to triggers in SQL. However, these additional functions that I can add are scripts written in javascript that run directly on the same server as the framework and as scripts they are easily readable. Obviously if I have created a component I don't necessarily want my customers, or potentially competitors, wanting to be able to see the code and use it. So, I'd like to be able to embed these functions in a code library or DLL. Any suggestions?

Thanks.
0
Comment
Question by:Lee Savidge
  • 7
  • 3
  • 2
  • +1
13 Comments
 
LVL 20

Expert Comment

by:BuggyCoder
Comment Utility
there are loads of obfuscators available that makes it harder to read your code,  but there is nothing till date that hides your code:-

here is a link:-
http://www.javascriptobfuscator.com/

see these discussions as well:-
http://stackoverflow.com/questions/1660060/how-to-prevent-your-javascript-code-from-being-stolen-copied-and-viewed
0
 
LVL 7

Expert Comment

by:designatedinitializer
Comment Utility
JavaScript runs on the browser, and you know it.
There are only 2 ways to run JavaScript into the browser:
1. One, is running it like we've all been doing. You can obfuscate it, but if it's readable by the browser it's also readable by the user.
2. The other, is by developing a browser plugin that users will need to install in their browsers.
That's been done before. There used to be these guys from a company named "Futuresplash" that (way back when) wrapped a little javascript animation library in a plugin. That eventually evolved into Flash.

Needless to say, your only hope (door number 2) is kinda cumbersome.
0
 
LVL 25

Author Comment

by:Lee Savidge
Comment Utility
I know with Javascript the end response is that you can't hide your code. I know there are code obfuscators but you can decode them easily. I'm happy to rewrite the functions in C# and embed them in a DLL so they return the data I need as long as the functionality is hidden. For example many of my functions will return strings after processing, or booleans. These can easily be written in C# as a DLL. So how would I call that DLL from a javascript?
0
 
LVL 25

Author Comment

by:Lee Savidge
Comment Utility
Just so we're clear, the javascript does not run client side. It is serverside javascript. It is never sent to the browser.
0
 
LVL 20

Expert Comment

by:BuggyCoder
Comment Utility
well you can always use AJAX to call a server side page, make your dll part of asp.net http handler and connect to that handler using AJAX. Here is an example:-

http://www.misfitgeek.com/2011/05/calling-web-service-page-methods-with-jquery/
http://brijbhushan.net/2011/05/29/call-httphandler-from-jquery-pass-data-and-retrieve-in-json-format/
0
 
LVL 5

Expert Comment

by:mvdeveloper
Comment Utility
To be clear - what application framework are you using to support the serverside javascript?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 25

Author Comment

by:Lee Savidge
Comment Utility
I think I need to explain more here.

The framework is an ISAPI DLL that lives on the server in IIS. The javascript code exists inside that framework. The javascript code makes calls INTO that ISAPI DLL via it's standard object interface. This javascript is not/does not/will not exist anywhere on the client because it is called by the ISAPI DLL on the server to process data on the server. The page at the point this code runs, does not exist. I cannot do alerts because there is no place to display alerts as there is no page at this point. The code does not interact with the end page or browser. It exists BEFORE the page is built on the server in IIS and runs in IIS's memory space. That is where my code already exists. I would like to move the functions and rewrite them as C#. I can do that already. I can write the DLL. What I can't seem to find out is how to call that DLL that will live on the server from that script.

For example, my code may do this:

var oOrg = FW.GetRec("Org", "IDField=" + IDField);

This returns an object from the object interface of the ISAPI dll. At this point I have full access to that Organisation object because the GetRec function requests an Org object type and the search parameter is the unique ID. The ISAPI dll then searches the database on the same server for that record. I can then play around with my record like this:

oOrg.name = "new name";
oOrg.status = "deleted";
oOrg.save;

This will write the data back through the existing DLL. At this point, the HTTP response has not even started building the page to send back to the browser. That bit is fine and nothing will change there. However I have some code libraries which do things that the standard framework interface does not do. For example:

Date handling and conversions
Basic logic on iterating through multiple objects when the GetRec returns more than one object. The search parameter field doesn't necessarily have to be the ID field. I can do a partial name search ie "NameField like '%" + name + "%'"

This returns an array that I can iterate through. All of my custom functions I would like to have in my DLL. I can already convert the code to C#. That's simple. I'm just not clear on instantiating an object from a class in a DLL on the server.
0
 
LVL 5

Expert Comment

by:mvdeveloper
Comment Utility
Ok I think I get the picture now.

In a sense, you're asking the wrong question .. javaScript is a scripting language, and so depends on the features provided to it in whatever context it is running. If, for example, you were running JS within Windows Scripting Host (WSH) you could instantiate a COM object and control that (e.g. System.FileScriptingObject for file access) but only because WSH makes that interface available. The JavaScript itself has no native means of doing that.

So the question is really, what features does your specific ISAPI DLL expose to support this?

If the DLL is itself allowing you to expose COM objects to your JavaScript - which seems likely from what you say above - then you can simply create a C# assembly and expose it for COM interop by either
a) going into the Assembly Properties and checking the Make Assembly COM Visible box, or b) by explicitly setting thye ComClass attribute on any class you wish to expose and using the GUIDGEN tool to set the class id and interface id.

But you need to contact whoever developed the ISAPI DLL you are using to find out what that supports. The JavaScript is only automating that.
0
 
LVL 25

Author Comment

by:Lee Savidge
Comment Utility
The ISAPI dll is not what I want to interact with. I can already do that because the interface is already created for me. I have additional functions which work well as SSJS and I can easily convert to C#. These functions take a string and return a processed string. There are plenty of others. It's just a library of functions that I find useful.

For example, I can make a connection to a database using SSJS with code like this:

var rs = new ActiveXObject("ADODB.Recordset")
var conn = new ActiveXObject("ADODB.Connection")

I can create a COM object myself in C# that contains equivalent functions to what my existing javascript library contains.

My code library contains functions like:

RemoveNonNumeric(inputString)
ProperCase(inputString)
ProcessLimited(inputString)
ProcessQuotes(inputString)

All of them take an input and return a string. This can be done in javascript, or if I were creating a Windows app, I may have a FunctionsLib class that contained a bunch of public functions that did the same as these examples above. If I created the FunctionLib class in C# and made the functions plublic I would call them in a way similar to this:

string sOut = "";
FunctionLib oFL = new FunctionLib();
sOut = oFL.ProcessQuotes(inputString);

If I were to do this from serverside javascript where I had registered the FunctionLib.dll, how would I call that from the javascript on the server?
0
 
LVL 5

Accepted Solution

by:
mvdeveloper earned 250 total points
Comment Utility
Since your SSJS has ActiveXObject,

var funcLib = new ActiveXObject("myAssembly.myClass");

Once you've exposed your C# class for com.
0
 
LVL 25

Author Comment

by:Lee Savidge
Comment Utility
I will be testing this sometime this week. Thanks for the suggestions so far.
0
 
LVL 25

Author Comment

by:Lee Savidge
Comment Utility
Other project work has got in the way of this. I have not yet managed to try this out. When I do I will update the question. Apologies for the delay.
0
 
LVL 25

Author Closing Comment

by:Lee Savidge
Comment Utility
I got this working in the end. Finally had time to try it.

Many thanks.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now