Can i generate a hash of a javascript file to check if it has been edited by the client? [closed] - javascript

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I am using https://pavlovia.org to run some experiments in behavioral economics in risky-choice. The task requires the subjects to play (or not) different lotteries. The system creates javascript files which it runs on the subject's browser. However, I found it very easy to inspect and edit the javascript which would allow a malicious subject to give themselves an advantage (e.g. increase the probability of a lottery paying out).
If someone makes all the lotteries "win", it will be easy to tell they cheated, but if they boost the probabilities by a small amount it will be very hard.
Other than re-writing everything so that the logic is server-side, I wondered whether it is possible to compute a hash (md5 or sha) of the JS code on the client and sent it back to the server to check wither the JS has been edited. I found several posts related to computing hashes in javascript, but I wasn't sure whether a file could compute its own hash.
I appreciate that a sophisticated user could also hack that part of the code (e.g. copy the original file to another name and then edit the code that takes the hash to point to the original file, or something like that). But i wonder if this technique could be one more barrier to cheating.

The user has the ability to debug the JS code while running and replace values in some variables. Even if JS hashing was possible, it would not prevent that. I believe there is no other way than making part of the crucial logic on the server side.

Related

Is it faster to upload one big file or more smaller ones? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
first of all I don't know if question like this already exists, I tried but couldn't find it, so if there is I apologize.
I am trying to stream video by sending each frame to client and then displaying it using Javascript on Website. (so it all works using WebSockets).
I host websocket server on a PC (c# is the language). So, I take screenshot of entire screen and immediately send it over to client.
Now, my question is: should I store multiple frames (say 3?) to one file, then upload that file or should I send frame by frame like I already do? I wonder which one is faster?
Thank you.
They are both going to upload the same size of file, one will be split up though so. They should theoretically upload at the same time- this all depends on bandwith also.
I believe that either way they will be split into packets when they cross networks, so it is more about how you would like to deal with the frames on the client side. If I were you I would let the lower technologies handle details like this (e.g the frameworks or libraries you are using) unless you have a specific purpose for sending the frames in intervals because it will add time on to the upload and it adds more room for things to go wrong with separate loads of frames. E.g; you could send the split frames in the wrong order.

Best Practices: Website and Database Integration [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
What are the pros and cons of different methods of including data from a database on your webpage?
From my understanding I have two options. A html page, with JavaScript (or other browser language) that fetches and includes data. A php script (or other server based program) that builds and outputs an html page with the data already included. But how am I to made the decision between the two?
Always go for PHP when using a database. It is a more robust and proven technique.
Also PHP pages are protected by the server and nobody can see how the code works, they only see HTML output, whereas with Javascript anyone can see your code.
After all I don't know how JS supposed to interact with data, maybe store data in an XML page and then retrieve them, not sure. Why invent a wheel when you have PHP which is supposed to work with databases unlike JS which is designed mostly to be an improved front end functionality, unless its back end JS, but few people use JS that way.

Which is more preferable in terms of performance Javascript and jQuery or PHP given same type of work [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Description :
I have couple of functions that can be written in JavaScript and PHP aswell.
e.g
(a) Current datetime calculation and their subtraction
(b) String replace , extracting substring , checking for a position of character in string and many more
I can submit the data in two ways either I can perform all the calculations and functions on client side using JavaScript
OR
I can send all the raw data to php and do the exact same work in PHP there before saving it in the database.
My Question :
What should I focus on more and try to write as much as I can in either of the languages ?
If performance is what you're after, do as much as you can in javascript, because client's computer tends to have more free computing power than your server. That is because a client only has to do it for himself, server would need to do it for all visitors - possibly thousands upon thousands. Expected client base is a major factor here.
However, take into consideration that a client can't be "trusted"; if you're going to insert something in database, verify everything that needs to be right.
If supporting visitors without javascript is something you'd care to do, you obviously have to move everything server side, but that is rarely the case nowadays.
If anything that you are trying to do is for validation, then do it on the server side with PHP. The client side is untrustworthy and unreliable for that sort of thing.
As far as efficiency goes, in terms of calculations/processing power, your server is likely going to be beefier than the client. You may have a client with a beast of a machine, but gnerally speaking your server's hardware out perform the client hardware. Better to keep as much of your processing you can on the server.

Client-Side vs. Server-Side Scripts to Process Order [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am designing a website to allow the user to pick the size of their pizza and the toppings they put on it. Based on these choices, I want to write scripts to:
1. calculate the cost for that pizza when the form is submitted
2. Process payment (validate Credit Cards, etc )
After reading countless articles, it appears obvious that I have to do all the payment processing server-side (php). For the form validaton which will determine which toppings and size the user picked and determine a price for that pizza, should I do that server side or is it better to do it client side (javascript) ? Thank you!
It is probably best to do a little of both. If you do it client-side, the user will be able to alter the values using inline javascript, which is a security vulnerability. Javascript validation is much faster and more convenient than server-side validation. Best practice is do both.
Client side is optional, it can save you doing round trips to the web server every time you want something done. Server side is not, well not unless you already have a free meal deal for hackers.

Real time collaborative use interface on the web [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm wondering what the technologies and best practices are behind real time collaboration in web interfaces.
An example of this is of course Google Wave. Another is PivotalTracker.com.
I'm particularly interested in any work (frameworks, plugins, etc) people are doing with Ruby on Rails here.
I imagine it would have to use Javascript underneath at some level, but you would need a way to abstract this out. Probably polling the server periodically to see if changes have been made, and also a way to resolve conflicts if in the middle of editing something the server comes back and says someone else has updated it.
Thank you!
Wave has operational transform that has a nice property of being easily combinable. You have two users, each of them does "something" in the user interface and two "somethings" can be combined into final document. That allows you to skip the problems with conflict resolution.
A nice way to enable real-time updates to state of the app is by using Comet, which is essentially a geeky codename for keeping an alive, long standing, unterminated get/post request to the server, that server finishes and responds to when something happens on the server. It allows sending to the client instantaneous updates without having the client periodically poll.
I can't really say how to abstract this away in javascript/r'n'r, many of the underlying technical details are hard enough and application specific that no framework supports them out of the box.

Categories