You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The`sandbox`attribute allows for the exclusion of certain actions inside an `<iframe>` in order to prevent it executing untrusted code. It "sandboxes" the iframe by treating it as coming from another origin and/or applying other limitations.
215
+
L'attributo`sandbox`permette l'esclusione di determinate azioni all'interno di un `<iframe>`, in modo da prevenire l'esecuzione di codice non affidabile. Consente di "isolare" ("sandbox") l'iframe, facendo si che venga trattato come se appartenesse ad un origine diversa e/o applicando altre limitazioni.
216
216
217
-
There's a "default set" of restrictions applied for`<iframe sandbox src="...">`. But it can be relaxed if we provide a space-separated list of restrictions that should not be applied as a value of the attribute, like this: `<iframe sandbox="allow-forms allow-popups">`.
217
+
Ci sono una serie di restriozioni "applicate di default" per un`<iframe sandbox src="...">`. Ma possono essere disattivate esplicitamente fornendo, come valore dell'attributo, la lista delle restrizioni da non applicare separate da un carettere di spazio, in questo modo: `<iframe sandbox="allow-forms allow-popups">`.
218
218
219
-
In other words, an empty`"sandbox"`attribute puts the strictest limitations possible, but we can put a space-delimited list of those that we want to lift.
219
+
In altre parole, un attributo`"sandbox"`vuoto, applica tutte le restrizioni, ma possiamo fornirgli la lista di quelle che vogliamo disattivare, separandole con uno spazio.
220
220
221
-
Here's a list of limitations:
221
+
Di seguito la lista delle limitazioni:
222
222
223
223
`allow-same-origin`
224
-
: By default `"sandbox"`forces the "different origin" policy for the iframe. In other words, it makes the browser to treat the `iframe`as coming from another origin, even if its `src`points to the same site. With all implied restrictions for scripts. This option removes that feature.
224
+
: Di default l'attributo `"sandbox"`forza la politica di "diversa origine" per un iframe. In altre parole, fa si che il browser trati l'`iframe`come se appartenesse ad un origine diversa, anche se in realtà il suo `src`sta puntando allo stesso sito. Con tutte le relative implicazioni viste prima. Questa opzione, disabilita la restrizione.
The example below demonstrates a sandboxed iframe with the default set of restrictions: `<iframe sandbox src="...">`. It has some JavaScript and a form.
240
+
L'esempio sotto dimostra un iframe "isolato" con le restrizioni di default attivate: `<iframe sandbox src="...">`. Contiene del codice JavaScript ed un form.
241
241
242
-
Please note that nothing works. So the default set is really harsh:
242
+
Avrete notato che nulla di ciò che è presente funziona. Quindi le restrizioni di default sono piuttosto restrittive:
243
243
244
244
[codetabs src="sandbox" height=140]
245
245
246
246
247
247
```smart
248
-
The purpose of the `"sandbox"` attribute is only to *add more* restrictions. It cannot remove them. In particular, it can't relax same-origin restrictions if the iframe comes from another origin.
248
+
Lo scopo dell'attributo `"sandbox"` è solamente quello di *aggiungere più* restrizioni. Non di diminuirle. In particolare, non può essere utilizzato per disabilitare la restrizione di "Same Origin" per iframe appartengono ad origini differenti.
249
249
```
250
250
251
-
## Cross-window messaging
251
+
## Messaggi Cross-window
252
252
253
-
The`postMessage`interface allows windows to talk to each other no matter which origin they are from.
253
+
L'interfaccia`postMessage`permette alle finestre di comunicare indistintamente dall'origine di appartenenza.
254
254
255
-
So, it's a way around the "Same Origin" policy. It allows a window from `john-smith.com`to talk to`gmail.com`and exchange information, but only if they both agree and call corresponding JavaScript functions. That makes it safe for users.
255
+
Quindi, è di fatto un modo per aggirare la politica di "Same Origin". Consente infatti ad una finestra proveniente da `john-smith.com`di comunicare con`gmail.com`e scambiarsi informazioni, ma solamente nel caso in cui entrambe acconsentono questo comportamento ed invocano le rispettive funzoni JavaScript. Questo rende il meccaniscmo di comunicazione tra finestre sicuro per l'utente.
256
256
257
-
The interface has two parts.
257
+
L'interfaccia è composta da due parti.
258
258
259
259
### postMessage
260
260
261
-
The window that wants to send a message calls [postMessage](mdn:api/Window.postMessage)method of the receiving window. In other words, if we want to send the message to `win`, we should call `win.postMessage(data, targetOrigin)`.
261
+
La finestra che vuole inviare un messaggio invoca il metodo [postMessage](mdn:api/Window.postMessage)della finestra destinataria. In altre parole, se volessimo inviare un messaggio a `win`, dovremmo invocare`win.postMessage(data, targetOrigin)`.
262
262
263
-
Arguments:
263
+
Argomenti:
264
264
265
265
`data`
266
-
: The data to send. Can be any object, the data is cloned using the "structured serialization algorithm". IE supports only strings, so we should`JSON.stringify`complex objects to support that browser.
266
+
: I dati da inviare. Possono essere un qualsiasi oggetto, che verrà poi duplicato utilizzando "l'algorito di serializzazione strutturato". IE supporta solamente stringhe, quindi dovremo utilizzare`JSON.stringify`per supportarlo.
267
267
268
268
`targetOrigin`
269
-
: Specifies the origin for the target window, so that only a window from the given origin will get the message.
269
+
: Specifica l'origine per al finestra target, in questo modo il messaggio verrà ricevuto solamente dalla giusta finestra.
270
270
271
-
The `targetOrigin`is a safety measure. Remember, if the target window comes from another origin, we can't read it's `location`in the sender window. So we can't be sure which site is open in the intended window right now: the user could navigate away, and the sender window has no idea about it.
271
+
Il parametro `targetOrigin`è una misura di sicurezza. Ricordate, se una finestra target appartiene ad una diversa origine, non possiamo leggere la sua `location`nella finestra mittente. Quindi non possiamo essere certi di quale sito sia aperto nella finestra a cui vogliamo inviare il messaggio: l'utente potrebbe aver cambiato sito, senza che la finestra mittente ne sia al corrente.
272
272
273
-
Specifying `targetOrigin`ensures that the window only receives the data if it's still at the right site. Important when the data is sensitive.
273
+
Specificando la proprietà `targetOrigin`ci assicuriamo che la finestra riceva i dati solamente se si trova nel sito che ci aspettiamo li riceva. Questa caratteristica è molto importante, specialmente per dati sensibili.
274
274
275
-
For instance, here `win`will only receive the message if it has a document from the origin`http://example.com`:
275
+
Ad esempio, in questo caso `win`riceverà il messaggio solamente se si trova nel sito`http://example.com`:
276
276
277
277
```html no-beautify
278
278
<iframesrc="http://example.com"name="example">
@@ -284,7 +284,7 @@ For instance, here `win` will only receive the message if it has a document from
284
284
</script>
285
285
```
286
286
287
-
If we don't want that check, we can set `targetOrigin`to`*`.
287
+
Se non abbiamo intenzione di effettuare tale verifica, possiamo impostare `targetOrigin`a`*`.
288
288
289
289
```html no-beautify
290
290
<iframesrc="http://example.com"name="example">
@@ -301,70 +301,72 @@ If we don't want that check, we can set `targetOrigin` to `*`.
301
301
302
302
### onmessage
303
303
304
-
To receive a message, the target window should have a handler on the `message` event. It triggers when `postMessage`is called (and `targetOrigin`check is successful).
304
+
Per poter ricevere un messaggio, la finestra target deve aver definito un handler per gestire l'evento `message`. Questo verrà innescato al momento dell'invocazione di `postMessage`(se la verifica del `targetOrigin`avrà successo).
305
305
306
-
The event object has special properties:
306
+
L'oggetto innescato dall'evento possiede le seguenti proprietà:
307
307
308
308
`data`
309
-
: The data from`postMessage`.
309
+
: I dati inviati da`postMessage`.
310
310
311
311
`origin`
312
-
: The origin of the sender, for instance`http://javascript.info`.
312
+
: L'origine del mittente, ad esempio`http://javascript.info`.
313
313
314
314
`source`
315
-
: The reference to the sender window. We can immediately `source.postMessage(...)` back if we want.
315
+
: Il riferimento alla finestra mittente. Potremmo quindi rispondere immediatamente utilizzando `source.postMessage(...)`, se è ciò che vogliamo fare.
316
316
317
-
To assign that handler, we should use `addEventListener`, a short syntax `window.onmessage` does not work.
317
+
Per assegnare il gestore, dovremo utilizzare `addEventListener`. Non abbiamo a disposizione la sintassi abbreviata `window.onmessage`,
//something from an unknown domain, let's ignore it
324
+
//qualcosa da un dominio sconosciuto, lo ignoriamo
325
325
return;
326
326
}
327
327
328
328
alert( "received: "+event.data );
329
329
330
-
//can message back using event.source.postMessage(...)
330
+
//rispondiamo al messaggio utilizzando event.source.postMessage(...)
331
331
});
332
332
```
333
333
334
-
The full example:
334
+
Ecco l'esempio completo:
335
335
336
336
[codetabs src="postmessage" height=120]
337
337
338
-
## Summary
338
+
## Riepilogo
339
339
340
-
To call methods and access the content of another window, we should first have a reference to it.
340
+
Per poter invocare metodi ed accedere al contenuto di un'altra finestra, dobbiamo come prima cosa ottenere un riferimeto ad essa.
341
341
342
-
For popups we have these references:
343
-
-From the opener window: `window.open` -- opens a new window and returns a reference to it,
344
-
-From the popup: `window.opener` -- is a reference to the opener window from a popup.
342
+
Per le finestre di popup abbiamo i seguenti riferimenti:
343
+
-Dalla finestra che innesca l'apertura: `window.open`, consente di aprire una nuova finestra e ne ritorna il riferimento,
344
+
-Dalla finestra di popup: `window.opener`, è il riferimento alla finestra che ha innescato l'apertura.
345
345
346
-
For iframes, we can access parent/children windows using:
347
-
-`window.frames` -- a collection of nested window objects,
348
-
-`window.parent`, `window.top`are the references to parent and top windows,
349
-
-`iframe.contentWindow`is the window inside an `<iframe>` tag.
346
+
Per gli iframe, possiamo accedere alle finestre padre/figlie utilizzando:
347
+
-`window.frames`, una collection di oggetti relativi alle finestre annidate,
348
+
-`window.parent`, `window.top`sono i riferimenti alle finestre padre e alla figlia,
349
+
-`iframe.contentWindow`è la finestra all'interno di un tag `<iframe>`.
350
350
351
-
If windows share the same origin (host, port, protocol), then windows can do whatever they want with each other.
351
+
Se le finestre condividono la stessa origine (host, porta e protocollo), allora queste potranno accedere liberamente alle proprietà.
352
352
353
-
Otherwise, only possible actions are:
354
-
-Change the`location`of another window (write-only access).
355
-
-Post a message to it.
353
+
Altrimenti, le uniche azioni possibili saranno:
354
+
-Cambio di`location`di un'altra finestra (accesso in scrittura).
355
+
-Inviare un messaggio.
356
356
357
-
Exceptions are:
358
-
-Windows that share the same second-level domain: `a.site.com`and`b.site.com`. Then setting `document.domain='site.com'` in both of them puts them into the "same origin" state.
359
-
-If an iframe has a`sandbox` attribute, it is forcefully put into the "different origin" state, unless the `allow-same-origin` is specified in the attribute value. That can be used to run untrusted code in iframes from the same site.
357
+
Le uniche eccezioni sono:
358
+
-Finestere che condividono lo stesso dominio di secondo livello: `a.site.com`e`b.site.com`. E che abbiamo entrambe impostato: `document.domain='site.com'`. In questo caso verranno intepretate come appartenenti alla stessa origine.
359
+
-Se un iframe possiede l'attributo`sandbox`, allora questo verrà forzato ad uno stato di "origine differente", a meno che non venga esplicitamente disattivato passando come valore dell'attributo `allow-same-origin`. In questo caso verrà permessa l'esecuzione di codice esterno all'interno dell'iframe (se appartengono alla stessa origine).
360
360
361
-
The `postMessage` interface allows two windows with any origins to talk:
361
+
L'interfaccia `postMessage` consente a due finestre, qualsiasi sia la loro origine, di comunicare:
362
+
363
+
1. Il mittente invocherà `targetWin.postMessage(data, targetOrigin)`.
364
+
2. Se `targetOrigin` non è impostato a `'*'`, allora il browser verificherà se la finestra `targetWin` appartiene all'origine `targetOrigin`.
365
+
3. Se questo è il caso, allora `targetWin` innescherà l'evento `message`, il quale possiede le seguenti proprietà:
366
+
-`origin`: l'origine della finestra mittente (ad esempio `http://my.site.com`)
367
+
-`source`: il riferimento alla finestra mittente.
368
+
-`data`: i dati inviati, sono supportati tutti i tipi di oggetto, ad eccezione di IE che accetta solamente stringhe.
369
+
370
+
Dobbiamo utilizzare `addEventListener` all'interno delle finestra targer, per impostare il gestore dell'evento.
362
371
363
-
1. The sender calls `targetWin.postMessage(data, targetOrigin)`.
364
-
2. If `targetOrigin` is not `'*'`, then the browser checks if window `targetWin` has the origin `targetOrigin`.
365
-
3. If it is so, then `targetWin` triggers the `message` event with special properties:
366
-
-`origin` -- the origin of the sender window (like `http://my.site.com`)
367
-
-`source` -- the reference to the sender window.
368
-
-`data` -- the data, any object in everywhere except IE that supports only strings.
369
372
370
-
We should use `addEventListener` to set the handler for this event inside the target window.
0 commit comments