I'm working on an extension that injects script in a page.
The extension is basically a content script that injects another script into the DOM. ( Why not just a content script? )
(There aren't any issues with my code, it works fine. The main purpose here is to learn about security issues in web development only)
The injected script is a source file in my extension and I get it with JQuery.get, using the address from chrome.extension.getURL('myscript.js')
.
Are there any security issues I should be aware of?
The page is not https
, can this get
return something different from my script?
I also insert HTML content using the same method. The HTML file is from my extension, just like the scritp. Is there any possibility of the responsetext be corrupted by a man in the middle??
What are the common practices to avoid such security issues if they exist?
Differently, if I create a script (document.createElement('script')
) and set its source to my file. Would it be possible for someone to interfere when I inject this cript into the dom? (document.documentElement.appendChild(myScipt)
)
Also, what are the security issues involving this approach? Injecting a script that changes the XMLHttpRequest
methods open
and send
in order to capture ajax calls, add listeners and send them with the same exact original arguments.
So, namely, say I have these:
var myScript = document.createElement('script');
myScript.src = chrome.extension.getURL('myscript.js');
var page = chrome.extension.getURL('mypage.html');
- In such context, can a
$.get('mypage.html')
return anything different from my page due to a man in the middle? (In other words, could I unknowingly inject a malicious page?) - Could a
document.documentElement.append(myScript)
inject a different script? Could a supposed man in the middle get between the.src
and change the actual script? - Since the script is meant to change the
XMLHttpRequest
prototype as described in the linked approach, could I eversend
with arguments different from those passed by the original call?
Thank you!