18
I have in my document one iframe
with the attribute sandbox
.
With javasript
i do reading a file Markdown
and parse using the library showdonwjs and add that result to the attribute srcdoc
of iframe
and the result is the expected.
However the files come from the origin of the users and will be visible to other users so I make use of the attribute sandbox
.
When in the file Markdown
there is a script... the page where the iframe
throws an error in the console
browser (obvious if the attribute prevents execution, when there is an attempt there must be an error).
How can I (if I can) observe this error in javascript
? Know if there’s been a mistake?
Thanks in advance.
update
page.html
<!DOCTYPE html>
<html lang="">
<head>
<title>Teste</title>
</head>
<body id="body">
<iframe id="frame" sandbox></iframe>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="https://rawgit.com/showdownjs/showdown/develop/dist/showdown.min.js"></script>
<script type="text/javascript">
var md = '###Hello Word <script>alert("!")<\/script>';
var converter = new showdown.Converter();
var MDtoHTML = converter.makeHtml(md)
var ifrm = $('#frame')
ifrm.attr('srcdoc', MDtoHTML);
</script>
</body>
</html>
jsFiddle Exeplo
Well that is the print of the said error! It happens so I believe that my doubt has at least sense! Could (if possible "observe") display a pop-up, banner or even log, identify malicious Uploaders.
You can do a jsFiddle with an example of what you’re doing?
– Sergio
I even tried using the bad Fiddle I could not. I will update the question and put part of the code.
– Lauro Moraes
Added example in jsFiddle: https://jsfiddle.net/hgmzov4g/
– Lauro Moraes
Related: http://answall.com/q/142711/3635
– Guilherme Nascimento
I didn’t see what could be related. In the example question the user wants to run javascript in iframe Sandboxed which is exactly what I don’t want.
– Lauro Moraes
Unrelated is not the same, if you look at the code I explain how to get the log, isn’t that what you want? And understand that related does not mean duplicated, the link only serves to help future visitors ;)
– Guilherme Nascimento
@Guilhermenascimento I didn’t say "duplicated"... but I think you read the question not the content of it. Mine
iframe
does not have permissions on the attributesandbox
that is, it does not execute scripts.– Lauro Moraes
@Guilhermenascimento Truth that I do not know where the error is thrown but I believe to be the document that carries the
iframe
. I followed (yesterday) your link and tested with aiframe
no permissions and the error was the same until "printei" your example https://i.stack.Imgur.com/y8Eac.png– Lauro Moraes
The message says that allow-script was not set, but the example I posted has yes this:
<iframe id="fiddle-sandbox" sandbox="allow-same-origin allow-scripts allow-popups allow-forms allow-modals"></iframe>
, I’ll test it here.– Guilherme Nascimento
Like I said, you didn’t read my question. My iframe does not have permissions in the sandbox attribute... to test your example I removed the permissions because "the idea is not to execute javascript in iframe" I only want to "observe" this exception to be able to treat or show an alert (in the source document)
– Lauro Moraes
@Excuse me for asking, but what would this information be used for? I mean, even if you identify that there is javascript in the user’s markdown that doesn’t mean immediately that it is malicious. After all, markdown supports javascript examples.
– Genos
@Lauromoraes I have been researching about your question today for a long time, I believe it is not possible to capture this exception because it happens inside the iframe in sandbox mode, that is, not even the view that exposes it has access since allow-same-origin is not enabled. My suggestion is: try to implement or search for a javascript Sanitizer to check the user input, if the input does not pass in one of these Sanitizer means that it has a possible "malicious" code, it is an exit to your problem
– Fernando Farias
Because it is I searched in MDN, in W3C and in HTML SPEC and I find a hundred (seriously hundred) sites and nothing. I find it strange if it was to what seems an internal treatment of the browser I could not even find reference on Chrome or Firefox...
– Lauro Moraes
@Lauromoraes as he did not use the arroba
@GuilhermeNascimento
I didn’t get your message, some time ago, you said I didn’t read it, but that’s not what I meant, the problem is I’m trying to explain one thing to you and you’re clinging to another. I was just explaining the control that it is possible to have over IFRAME through the attributesandbox="..."
. I did not say that your iframe possesses, I said just the opposite. I cannot say that it is possible to get the errors of the console directly from iframe, but it is possible to obtain in the global scope. There is a link on the subject, I will post here.– Guilherme Nascimento