Using functions from my website in chrome console or firefox console? - javascript

I have a webpage up and running that has two js files with a bunch of functions. My HTML code loads these scripts as modules on startup. Problem is that i have a function called "showAdminTools()" and im afraid that this functions perhaps can be accessed through the chrome dev tools by non admins?

If the user isn't an admin, then don't send anything to their browser which should only be available to admins.
If the script is sensitive, then put it behind Authn/Authz and don't include it in a <script> if the user isn't an admin.

Yes everyone can access them with the console.

Actually im stupid, i already have server side code that prevents requests from client unless the user already is admin, so it does not matter if they can go into admin tools or not, any request from the admin tools page will be denied by server...
SORRY FOR WASTING TIME

Related

How to call browser extension from Javascript

I am using Protractor to test Angular JS content of an application.
As part of my automation scripts, i have to launch a application url and then call browser extension .
On clicking the browser extension - i am getting this URL
"chrome-extension://glfffgjbfebdaehgdcaachlfcpkggbbc/html/options.html#"
I have tried some solutions stated on google forums like, but the extension from automation script is getting launched.
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/extension/getURL
Programmatically open a Chrome plugin's options.html page?
Due to security purposes, i am not sharing the code. I request someone to advise me on how to achieve this task. Thanks !
You can't. Browser extensions run isolated to the other components for security reasons. They can only access the webpage not the other way around. That is also very limited. The variables in console environment of a page cannot be accessed by the extension and so the other way around.
You can try web-accessible-resources if you own the extension otherwise not much you can do.

Should chrome extensions have access to Tabs content (other websites)

Is there a way to identify and block JS files/events that are not part of your domain?
Like assume, if I'm writing a extension for chrome and I put following code in my JS
$('div').on('click', function(){ alert("yup"); });
is there a way for a website to handle this case?
Edit 1:
After discussion with #Clive, I realized that all extension/application should run in sandbox and should not be able to access events/elements outside the scope.
Case
A chrome extension have a keypress event on input[type=text] and input[type=password]. Now this extension runs in background, so there JS files are always available. Hence if you open facebook and login to your account, this extension will capture data and can send it to its server.
My Case
Two user was getting alert messages multiple times. Initially we thought its a part of our code and checked all JS files. But then realized, both user had same extension and so we diagnosed that extension's JS file and found alert in it. Now we were lucky, no damage was done, but it still posses a possible security threat.
Short answer: No.
Long answer:
Chrome extensions run their code in a separate space from your site's code, so they don't interact at all. The best you could do is prevent DOM edits. Luckily chrome extensions already run in a sandbox and have to explicitly ask for permissions for the domains that they inject code in and those domains are all listed when you install an extension. The only other way for extensions to interact with a page is through the activeTab permission which is a one time allowance on a specific user action. If you are using an extension that you think is malicious, you can always just read the code since JS is naturally open source. It really all boils down to a matter of trust. Installing something is explicitly trusting that thing to not mess up your stuff. This applies to all programs. If you don't trust an extension, then don't install it. A sandbox can only prevent so much while still letting extensions do something.

HTML to run javascript even when page is closed

Okay, this is a problem I have been having for sometime now, and I cant find a solution, Anywhere!
My Problem:
My HTML content is available as web application that can be used offline, but I want the contact form to also be available offline.
Is there anyway the user can fill in the contact form when they have no connection and then for a script to run that holds that inputted data until a connection is established.
And then once the connection is established for the data to be sent to a PHP script on a server?
Edit:
Thanks for all your answers! I have looked into local storage but this doesnt work as the user may revist the page but they still probably wont have an internet connection, so I was wondering if there is any type of script that can run locally all the time until there is an established internet connection
Thank you in advance!
You can not run a script unless the page is opened.
The only way around this would be to create a Chrome Extention or FireFox Addon:
http://en.wikipedia.org/wiki/Google_Chrome_Extensions
http://en.wikipedia.org/wiki/Add-on_(Mozilla)
Yes - provided that they open your page again with an internet connection at a later date.
The steps are:-
Try and send message (AJAX etc.)
If it fails due to no connection - store to localstorage.
Have a loop that checks for messages in local storage.
If message found try to re-send.
Once message is sent remove it from local storage. (AJAX success)
That is indeed possible if the website stays open.
You can have a javascript loop that checks some recource (i.e. a tiny json file on your server) and if it can read this successfully, it attempts to send the email/data.
If it is not, it waits for a certain time using timeout.
You'll surely be able to find examples of this on the internet since this is often used in modern web development due to the often unstable connection of smartphones.
you can try local storage to store the data and retrieve it after the browser re-opens Or cookies.
If you use mozilla you can hack the XUL codes and inject your scripts into it. Otherwise you must hack the browser template which supports js

What is "chrome-extension://"

I found the some strange <script/> tags on a site:
<script src="chrome-extension://lifbcibllhkdhoafpjfnlhfpfgnpldfl/document_iterator.js"></script>
<script src="chrome-extension://lifbcibllhkdhoafpjfnlhfpfgnpldfl/find_proxy.js"></script>
...
I haven't been able to find much information on this, but I highly doubt this is actually related to Google Chrome since this site in particular is still using <table>s for layout, and the source in question was retrieved with curl not a graphical web browser.
So,
What on earth is this?
What is chrome-extension://
Why is it using lifbcibllhkdhoafpjfnlhfpfgnpldfl as a directory name
Why is it pretending to be valid URL to a javascript file?
Why would I need find_proxy or document_iterator
Solved. As far as I know...
chrixian was right, It seems that only on this and a few select other pages, someone had re-saved them from Chrome's source-view with the Skype extension installed.
Thanks everyone for all your help, +1's for all! enjoy!
That is actually Skype Click to Call chrome extension.
Manage and view it using this link
chrome://extensions/?id=lifbcibllhkdhoafpjfnlhfpfgnpldfl
If you are using cURL to get the page, you're getting the HTML as it exists on the server--so I think a safe assumption would be: the author of the page initially saved the page from Chrome, he had an extension installed that inserted these script tages and lastly he didn't remove the script tags for one reason or another before putting the page on the server.
This is added by chrome as the page loads, to inject the extension's Javascript code into the page, so it can access the HTML document.
The Skype extension causes it by inserting all kinds of junk in webpages that you visit.
Do you have the Skype browser extension installed for Chrome?
Just disable the extension.
Chrome, like Firefox, provides developers with an easy API to extend the functionality of the web browser without needing to actually download and build the browser to do so.
They also provide a robust delivery system. In Google's case, it's the Google Chrome Web Store.
Extensions are installed locally on your computer, and use long strings as directory names to reduce the risk of collisions with another extension. In other words, if you and I both named our extensions "mycoolextension", then there would be a problem if a person tried to install your extension and my extension. The long string helps prevent collisions such as this.
The chrome-extension:// protocol is used by the browser to make requests to these local resources. Chrome extensions are developed using HTML5, JavaScript, and CSS, along with an API exposed to allow the local JavaScript to perform actions it would not normally be able to do on the Internet.
When you see these in the Chrome developer tools, it's just the extension doing it's thing, whatever that may be.
If you're seeing these, then you likely installed some extensions from the Chrome Web Store. To view them, go to the Tools menu and select "Extensions". This will show you a list of all installed Chrome extensions and apps.
To learn more about extension development, see the Getting Started Tutorial.
Also, as someone else mentioned, you're using the Skype Call Extension. However, an app using that directory name doesn't appear in the first page of the search results. It might be worth doing some more research to make sure you got that extension from a legitimate source, whether that be Skype or the Chrome Web Store.
If you're seeing it in Chrome developer tools for every request you make, it means it has access to all your websites, which could be benign, like if they're just making phone numbers clickable, or it could be malicious, if it's scraping your bank account info and shipping it off to some third party server. :)
It's a Chrome extension, and chrome-extension:// is a URL for extensions to address their contents via Javascript.
lifbcibllhkdhoafpjfnlhfpfgnpldfl is the unique identifier for the extension. I can't find it with a search, but apparently it might be Skype.
It's not pretending... it is a valid URL. The Javascript file is located in the extension. If you were to look on your harddrive you'd probably find that very file in the extensions folder.
The functions its calling probably are some sort of detection used by the extension to see if it needs to enable itself.
See this for some additional information:
Checking if user has a certain extension installed

running javascript in IE without warning 'the webpage you are trying to access wants to run activex control'

is there anyway to stop popping up the warning message in IE when trying to execute javascript?
I want some solution which does not need modifying the settings in the IE manually by the user.
Thanks,
If the message is only appearing for you when you run the scripts locally and not for your visitors when you upload your scripts to the server, I'd suggest one of three things:
Have a test server that you can use to run the things you are developing. This will avoid issues that might come up when you are running scripts locally. Apache or IIS should allow you to do this, although you will have to research how to get the server you choose to use working like your production environment (example: PHP).
If you want to continue to test your scripts locally, you can give your pages the Mark of the Web (<!-- saved from url=(0014)about:internet -->). This will force the page to run in the Internet Security Zone and avoid the message you see when you open an HTML file containing script locally.
If there is some reason you can't give the pages the MOTW, you can configure Internet Explorer to allow scripts to execute locally (note this is a bit dangerous since local files containing script can do something malicious). Go to Tools > Internet Options > Advanced tab > scroll to the Security section and check Allow active content to run in files on My Computer
This only occurs when you open local files. And no; there's no way to avoid this.
Or so I thought.. Untill Grant Wagner came by and gave his two cents :)

Categories

Resources