Skip to content

Commit

Permalink
docs: add faq
Browse files Browse the repository at this point in the history
  • Loading branch information
Baroshem committed Sep 28, 2023
1 parent 40c6a72 commit 2f12bd6
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/content/1.documentation/2.headers/1.csp.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,9 @@ If you are unable or unwilling to use `useHead` and are inserting directly into
```ts
const nonce = useNonce()
```

You can then use it with Nuxt Image like following:

```html
<NuxtImg src="https://localhost:8000/api/image/xyz" :nonce="nonce" />
```
127 changes: 127 additions & 0 deletions docs/content/1.documentation/5.advanced/2.faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Frequently Asked Questions

Find answers for difficult questions.

---

## Testing CORS configuration

In the default configuration for CORS in Nuxt Security module, only the request that is coming from your origin (the same host by default) will be accepted and others will be rejected.

To test it, run your application and then in another test application running on a different port, send a request to the first app. You will get the CORS error there.

::alert{type="info"}
ℹ Read more about it [here](https://github.com/Baroshem/nuxt-security/issues/208).
::

## Set Content-Security-Policy-Report-Only

The HTTP Content-Security-Policy-Report-Only response header allows web developers to experiment with policies by monitoring (but not enforcing) their effects. These violation reports consist of JSON documents sent via an HTTP POST request to the specified URI.

You can add it to your project like this:

```ts
// nuxt.config.ts

routeRules: {
'/**': {
headers: {
'Content-Security-Policy-Report-Only': '<YOUR_DESIRED_VALUE>'
},
},
},
```

::alert{type="info"}
ℹ Read more about it [here](https://github.com/Baroshem/nuxt-security/issues/193#issuecomment-1669009189).
::

## Conflicting headers with Firebase Auth

When working with Firebase Auth, and more specifically the `signInWithPopup` method, you would need to disabled the following headers that are set by Nuxt Security automatically:

```ts
// nuxt.config.ts

security:{
headers: {
crossOriginOpenerPolicy: false,
crossOriginEmbedderPolicy: false,
}
}
```

::alert{type="info"}
ℹ Read more about it [here](https://github.com/Baroshem/nuxt-security/issues/127).
::

## Allowing images and scripts from external domains

In several situations you will need to allow fetching images from external domains. Here is how you can do that:

```ts
// nuxt.config.ts

security: {
headers: {
contentSecurityPolicy: {
'img-src': ['https://upload.wikimedia.org'], // <--- add the domain you want to fetch the image from here
}
}
}
```

Next, you need to configure your img tag to include the `crossorigin` attribute:

```html
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Cat_August_2010-4.jpg/272px-Cat_August_2010-4.jpg"
alt="Cat Image Here"
crossorigin
/>
```

::alert{type="info"}
ℹ Read more about it [here](https://github.com/Baroshem/nuxt-security/issues/138#issuecomment-1497883915).
::


## Using nonce with CSP for Nuxt Image

Having securely configured images is crucial for modern web applications. Check out how to do it below:

```ts
// nuxt.config.ts

security: {
nonce: true,
headers: {
contentSecurityPolicy: {
'img-src': ["'self'", 'data:', 'https:'],
'style-src': ["'self'", "'nonce-{{nonce}}'"],
'script-src': [
"'self'", // backwards compatibility for older browsers that don't support strict-dynamic
"'nonce-{{nonce}}'",
"'strict-dynamic'"
],
'script-src-attr': ["'self'", "'nonce-{{nonce}}'", "'strict-dynamic'"]
}
}
}
```

And then configure `NuxtImg` like following:

```vue
<template>
<NuxtImg src="https://localhost:8000/api/image/xyz" :nonce="nonce" />
</template>
<script lang="ts" setup>
const nonce = useNonce()
</script>
```

::alert{type="info"}
ℹ Read more about it [here](https://github.com/Baroshem/nuxt-security/issues/218#issuecomment-1736940913).
::

0 comments on commit 2f12bd6

Please sign in to comment.