I am getting the following error:
analytics.min.js:9 Refused to load the script 'https://cdn.amplitude.com/libs/amplitude-5.2.2-min.gz.js' because it violates the following Content Security Policy directive: "script-src 'self'
https://apis.google.com
https://cdnjs.cloudflare.com
https://cdn.segment.com
https://ajax.googleapis.com
https://*.woopra.com
[...]
http://www.luckyorange.com https://ssl.luckyorange.com https://d10lpsik1i8c69.cloudfront.net". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
in my glitch project. It's my first attempt at connecting to a MongoDB database
After doing some research on the error, I think I'm finally beginning to understand what content security policy is and how it prevents XSS, but I was still having problems with how to implement allowing the site in my project.
From the MDN article I found the syntax to implement this: Content-Security-Policy: <policy-directive>; <policy-directive>
but wasn't sure where this belonged, what file to put it in.
I did some more digging and found an html implementation in this stackoverflow article.
After some tinkering with it and clearing another error assiated with the omission of the samesite
attribute I finally got to a line that I think should be working: <meta http-equiv="Content-Security-Policy" content="default-src 'https://cdn.amplitude.com/libs/' 'unsafe-inline'" samesite="none">
; however, it is not.
index.html
:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to HyperDev!</title>
<meta name="" content="A cool thing made with HyperDev">
<link rel="shortcut icon" href="https://cdn.hyperdev.com/us-east-1%3A52a203ff-088b-420f-81be-45bf559d01b1%2Ffavicon.ico" type="image/x-icon"/>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="default-src 'https://cdn.amplitude.com/libs/' 'unsafe-inline'" samesite="none">
<style>
body {
background-color: #ddd;
color: #333;
font-family: sans-serif;
text-align: center;
}
</style>
</head>
</html>
package.json
:
{
"name": "fcc-mongo-mongoose-challenges",
"version": "0.0.1",
"description": "A boilerplate project",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.16.4",
"body-parser": "^1.19.0",
"mongoose": "^5.7.4",
"mongodb": "^3.3.2"
},
"engines": {
"node": "4.4.5"
},
"repository": {
"type": "git",
"url": "https://hyperdev.com/#!/project/welcome-project"
}
}
myApp.js
:
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI, {useNewUrlParser: true, useUnifiedTopology: true})
.catch(e=>console.log(e));
It is not passing this test on freecodecamp. Most likely due to the error listed above, the database is not connecting.