# Subresource Integrity (SRI)

## Descripción

Subresource Integrity (SRI) es una característica de seguridad que permite a los navegadores web verificar que los recursos que obtienen (por ejemplo, de un Content Delivery Networks) se entregan sin manipulaciones inesperadas. Es decir, le indica al navegador web que no cargue un recurso si el hash del recurso no coincide con un valor proporcionado previamente.

```html
<script src="https://example.com/script.js" integrity="sha384-tnzs0xPwekidEWHMZrWogzv1zrfOzlH18cCW2EMwMZ7uRe3NBceseD4AjA84jIKO" crossorigin="anonymous"></script>
```

El uso de Content Delivery Networks (CDN) para hospedar archivos de scripts y hojas de estilo que se comparten entre varios sitios puede mejorar el rendimiento del sitio. Sin embargo, el uso de CDN también conlleva un riesgo, ya que, si un atacante obtiene el control de una CDN, el atacante puede inyectar contenido malicioso arbitrario en los archivos del CDN (o reemplazar los archivos por completo) y, por lo tanto, también puede atacar potencialmente todos los sitios que obtienen archivos desde el CDN.&#x20;

Subresource Integrity (SRI) permite mitigar algunos riesgos de ataques como este, al garantizar que los archivos que obtiene la aplicación web (desde un CDN o cualquier otro lugar) se hayan entregado sin que un tercero haya inyectado ningún contenido adicional en esos archivos y sin que se hayan realizado otros cambios de ningún tipo en dichos archivos.

Calcular el hash de un archivo con OpenSSL.

```sh
cat <file> | openssl dgst -sha256 -binary | openssl base64 -A
cat <file> | openssl dgst -sha384 -binary | openssl base64 -A
cat <file> | openssl dgst -sha512 -binary | openssl base64 -A
```

## Herramientas

* [SRI hash generator](https://www.srihash.org/)

## Referencias

* [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ssd.mrw0l05zyn.cl/general/subresource-integrity-sri.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
