How to check the authenticity of a Chrome extensio

2019-02-16 12:59发布

问题:

The Context:

  • You have a web server which has to provide an exclusive content only if your client has your specific Chrome extension installed.
  • You have two possibilities to provide the Chrome extension package:
    1. From the Chrome Web Store
    2. From your own server

The problem:

  • There is a plethora of solutions allowing to know that a Chrome extension is installed:
    1. Inserting an element when a web page is loaded by using Content Scripts.
    2. Sending specific headers to the server by using Web Requests.
    3. Etc.
  • But there seems to be no solution to check if the Chrome extension which is interacting with your web page is genuine.
  • Indeed, as the source code of the Chrome extension can be viewed and copied by anyone who want to, there seems to be no way to know if the current Chrome extension interacting with your web page is the one you have published or a cloned version (and maybe somewhat altered) by another person.
  • It seems that you are only able to know that some Chrome extension is interacting with your web page in an "expected way" but you cannot verify its authenticity.

The solution?

  • One solution may consist in using information contained in the Chrome extension package and which cannot be altered or copied by anyone else:
    1. Sending the Chrome extension's ID to the server? But how?
      • The ID has to be sent by you and your JavaScript code and there seems to be no way to do it with an "internal" Chrome function.
      • So if someone else just send the same ID to your server (some kind of Chrome extension's ID spoofing) then your server will consider his Chrome extension as a genuine one!
    2. Using the private key which served when you packaged the application? But how?
      • There seems to be no way to access or use in any way this key programmatically!
  • One other solution my consist in using NPAPI Plugins and embed authentication methods like GPG, etc. But this solution is not desirable mostly because of the big "Warning" section of its API's doc.
  • Is there any other solution?

Notes

This question attempts to raise a real security problem in the Chrome extension's API: How to check the authenticity of your Chrome extension when it comes to interact with your services. If there are any missing possibilities, or any misunderstandings please feel free to ask me in comments.

回答1:

I'm sorry to say but this problem as posed by you is in essence unsolvable because of one simple problem: You can't trust the client. And since the client can see the code then you can't solve the problem.

Any information coming from the client side can be replicated by other means. It is essentially the same problem as trying to prove that when a user logs into their account it is actually the user not somebody else who found out or was given their username and password.

The internet security models are built around 2 parties trying to communicate without a third party being able to imitate one, modify or listen the conversation. Without hiding the source code of the extension the client becomes indistinguishable from the third party (A file among copies - no way to determine which is which).

If the source code is hidden it becomes a whole other story. Now the user or malicious party doesn't have access to the secrets the real client knows and all the regular security models apply. However it is doubtful that Chrome will allow hidden source code in extensions, because it would produce other security issues.

Some source code can be hidden using NPAPI Plugins as you stated, but it comes with a price as you already know.


Coming back to the current state of things:

Now it becomes a question of what is meant by interaction.

If interaction means that while the user is on the page you want to know if it is your extension or some other then the closest you can get is to list your page in the extensions manifest under app section as documented here

This will allow you to ask on the page if the app is installed by using

    chrome.app.isInstalled

This will return boolean showing wether your app is installed or not. The command is documented here

However this does not really solve the problem, since the extension may be installed, but not enabled and there is another extension mocking the communication with your site.

Furthermore the validation is on the client side so any function that uses that validation can be overwritten to ignore the result of this variable.

If however the interaction means making XMLHttpRequests then you are out of luck. Can't be done using current methods because of the visibility of source code as discussed above.

However if it is limiting your sites usability to authorized entities I suggest using regular means of authentication: having the user log in will allow you to create a session. This session will be propagated to all requests made by the extension so you are down to regular client log in trust issues like account sharing etc. These can of course be managed by making the user log in say via their Google account, which most are reluctant to share and further mitigated by blocking accounts that seem to be misused.



回答2:

I would suggest to do something similar to what Git utilises(have a look at http://git-scm.com/book/en/Git-Internals-Git-Objects to understand how git implements it), i.e.

Creating SHA1 values of the content of every file in your chrome-extension and then re-create another SHA1 value of the concatenated SHA1 values obtained earlier.

In this way, you can share the SHA1 value with your server and authenticate your extension, as the SHA1 value will change just in case any person, changes any of your file.

Explaining it in more detail with some pseudo code:

function get_authentication_key(){

    var files = get_all_files_in_extension,
        concatenated_sha_values = '',
        authentication_key;

    for(file in files){
        concatenated_sha_values += Digest::SHA1.hexdigest(get_file_content(file));
    }

    $.ajax({
  url: 'http://example.com/getauthkey',
  type: 'post'
  async: false,
  success:function(data){
         authentication_key = data;
  }
    })

    //You may return either SHA value of concatenated values or return the concatenated SHA values
    return authentication_key;  
}

// Server side code
get('/getauthkey') do
    // One can apply several type of encryption algos on the string passed, to make it unbreakable
authentication_key = Digest::<encryption>.hexdigest($_GET['string']);
return authentication_key;
end

This method allows you to check if any kind of file has been changed maybe an image file or a video file or any other file. Would be glad to know if this thing can be broken as well.