How to protect my Javascript from being accessed by other parties?

RobotRock

Simply put, I have a website with a Javascript library which includes ads through a script tag. Now I'm concerned that the implemented ads can access my Javascript library (also included through a script tag), which does Ajax calls to a server (on which the user has a session).

I am looking to guard my Javascript from influence of included Javascript of the ads, as I don't want the ad companies to be able to make Ajax calls. In doing this, I don't want to rely to serverside scripting outside my Javascript library (note that calls to the library cannot have serverside scripting) (although setting a htpasswd is possible i.e.).

An example would be:

Library.js (can have serverside scripting, an other domain)

var library = function(parameters) {
      return ajaxCallWithParameters(parameters);
}

Website Javascript: (cannot rely on serverside scripting)

toTable(library());

Included possibly malicious ads: (other domain)

sendToAdServer(library());

In the case of using serverside scripting I could simply do:

   <script>var <?php echo $somehowSyncedrandomByTime; ?> = function(parameters) {
          return ajaxCallWithParameters(parameters);
    }</script> <!-- included JS script of other domain which supplies AJAX -->

    <script>toTable(<?php echo $somehowSyncedrandomByTime; ?>());</script> <!-- current domain -->

    <script>sendToAdServer(???());</script> <!-- by including offsite ad script -->

This way, the ads cannot find the function in question. But the website cannot include serverside scripting, so I am looking for an alternative.

Is it possible to obscure my Javascript in a way that included Javascript from third parties cannot call/read it?

aefxx

Frankly, no, it's not possible to somehow obscure or protect your scripts against other scripts running in the same context/scope as yours. But you always have the possibility to lock third party scripts in an iframe - i.e., they won't be able to interact with your code in any way unless you provide an interface (e.g. social networks use this a lot).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to protect my Javascript from being accessed by other parties?

From Dev

How to protect JSON API from being accessed by anyone but my iOS client?

From Dev

Protect PDF docs from being directly accessed in URL

From Dev

Will this approach protect my database from being modified?

From Dev

How to protect columns in hibernate from being read

From Dev

How to protect bash function from being overridden?

From Dev

Java anti-hacking. How protect .class file from being changed in my jar

From Dev

How do I make my backspace key functional in a bash script for Linux being accessed remotely from Windows?

From Dev

Will sandboxing a program protect my computer from being damaged?

From Dev

How to set up a private mediawiki or wordpress site that can be accessed from my other laptop?

From Dev

How to hide individual XPages from being accessed from a webbrowser

From Dev

How can I protect a matrix in R from being altered by Rcpp?

From Dev

How can I protect sqlite db in android from being stolen

From Dev

How can i protect a property from being overwritten

From Dev

How to Protect Windows OS Image From Being Copied?

From Dev

protect images from being copied

From Dev

How can I prevent this script from being freely accessed?

From Dev

How can I prevent this script from being freely accessed?

From Dev

C# - How to lock a method from being accessed by multiple process

From Dev

How to protect my network?

From Dev

How can protect PostgREST from sql injection and other security issues?

From Dev

Prevent localhost express server from being accessed by other devices on the local network

From Dev

How can I protect my site from the multiple post requests?

From Dev

How can I protect my user passwords and passphrase from root

From Dev

How to protect my portable HDD from physical damage?

From Dev

How to protect my digital data from Solar Flares?

From Dev

How can I protect my .factory from minification?

From Dev

How can I protect my site from the multiple post requests?

From Dev

How can I protect my OLED screen from burn-in?

Related Related

  1. 1

    How to protect my Javascript from being accessed by other parties?

  2. 2

    How to protect JSON API from being accessed by anyone but my iOS client?

  3. 3

    Protect PDF docs from being directly accessed in URL

  4. 4

    Will this approach protect my database from being modified?

  5. 5

    How to protect columns in hibernate from being read

  6. 6

    How to protect bash function from being overridden?

  7. 7

    Java anti-hacking. How protect .class file from being changed in my jar

  8. 8

    How do I make my backspace key functional in a bash script for Linux being accessed remotely from Windows?

  9. 9

    Will sandboxing a program protect my computer from being damaged?

  10. 10

    How to set up a private mediawiki or wordpress site that can be accessed from my other laptop?

  11. 11

    How to hide individual XPages from being accessed from a webbrowser

  12. 12

    How can I protect a matrix in R from being altered by Rcpp?

  13. 13

    How can I protect sqlite db in android from being stolen

  14. 14

    How can i protect a property from being overwritten

  15. 15

    How to Protect Windows OS Image From Being Copied?

  16. 16

    protect images from being copied

  17. 17

    How can I prevent this script from being freely accessed?

  18. 18

    How can I prevent this script from being freely accessed?

  19. 19

    C# - How to lock a method from being accessed by multiple process

  20. 20

    How to protect my network?

  21. 21

    How can protect PostgREST from sql injection and other security issues?

  22. 22

    Prevent localhost express server from being accessed by other devices on the local network

  23. 23

    How can I protect my site from the multiple post requests?

  24. 24

    How can I protect my user passwords and passphrase from root

  25. 25

    How to protect my portable HDD from physical damage?

  26. 26

    How to protect my digital data from Solar Flares?

  27. 27

    How can I protect my .factory from minification?

  28. 28

    How can I protect my site from the multiple post requests?

  29. 29

    How can I protect my OLED screen from burn-in?

HotTag

Archive