-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vincent de Chefdebien
committed
Feb 21, 2023
1 parent
04ac937
commit ac3799b
Showing
19 changed files
with
149 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Pour démarrer le serveur | ||
- npm i | ||
- npm run dev | ||
- ouvrir http://localhost:3000 dans Firefox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Pour démarrer le serveur | ||
- npm i | ||
- npm run dev | ||
- ouvrir http://localhost:3000 dans Firefox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,8 @@ | ||
# vue-xss | ||
|
||
This template should help get you started developing with Vue 3 in Vite. | ||
|
||
## Recommended IDE Setup | ||
|
||
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin). | ||
|
||
## Customize configuration | ||
|
||
See [Vite Configuration Reference](https://vitejs.dev/config/). | ||
|
||
## Project Setup | ||
|
||
```sh | ||
npm install | ||
``` | ||
|
||
### Compile and Hot-Reload for Development | ||
|
||
```sh | ||
npm run dev | ||
``` | ||
|
||
### Compile and Minify for Production | ||
|
||
```sh | ||
npm run build | ||
``` | ||
Pour démarrer le backend | ||
- cd 2_vanilla-xss | ||
- npm run dev | ||
|
||
Pour démarrer le frontend | ||
- npm i | ||
- npm run dev | ||
- ouvrir http://localhost:4000 dans Firefox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Pour démarrer le serveur | ||
- npm i | ||
- npm run dev | ||
- ouvrir http://localhost:3000 dans Firefox | ||
|
||
Copier le code de csrf.html sur codepen.io pour tester une requete cross-site |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Pour installer la BDD | ||
- docker run --detach --name sqlidb -p 5000:3306 --env MARIADB_USER=mdbuser --env MARIADB_PASSWORD=mdbpassword --env MARIADB_ROOT_PASSWORD=mdbroot mariadb:latest | ||
|
||
Pour réinitialiser le contenu de la BDD | ||
- docker exec -i sqlidb mysql -u root -pmdbroot < init.sql | ||
|
||
Pour démarrer la BDD les fois suivantes | ||
- docker start sqlidb | ||
|
||
Pour démarrer le serveur | ||
- npm i | ||
- npm run dev | ||
- ouvrir http://localhost:3000 dans Firefox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Pour installer la BDD | ||
- docker run --detach --name sqlidb -p 5000:3306 --env MARIADB_USER=mdbuser --env MARIADB_PASSWORD=mdbpassword --env MARIADB_ROOT_PASSWORD=mdbroot mariadb:latest | ||
|
||
Pour réinitialiser le contenu de la BDD | ||
- docker exec -i sqlidb mysql -u root -pmdbroot < init.sql | ||
|
||
Pour démarrer la BDD les fois suivantes | ||
- docker start sqlidb | ||
|
||
Pour démarrer le serveur | ||
- npm i | ||
- npm run dev | ||
- ouvrir http://localhost:3000 dans Firefox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Pour démarrer le serveur | ||
- npm i | ||
- npm run dev | ||
- ouvrir http://localhost:3000 dans Firefox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Pour installer la BDD | ||
- docker run --detach --name sqlidb -p 5000:3306 --env MARIADB_USER=mdbuser --env MARIADB_PASSWORD=mdbpassword --env MARIADB_ROOT_PASSWORD=mdbroot mariadb:latest | ||
|
||
Pour réinitialiser le contenu de la BDD | ||
- docker exec -i sqlidb mysql -u root -pmdbroot < init.sql | ||
|
||
Pour démarrer la BDD les fois suivantes | ||
- docker start sqlidb | ||
|
||
Pour démarrer le serveur | ||
- npm i | ||
- npm run dev | ||
- ouvrir http://localhost:3000 dans Firefox | ||
|
||
Pour lancer les tests | ||
- npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Pour démarrer le serveur | ||
- npm i | ||
- npm run dev | ||
- ouvrir http://localhost:3000 dans Firefox | ||
|
||
Pour lancer les tests cypress | ||
- npm run test | ||
- e2e tests dans chromium |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Code adapté de https://github.com/cornflourblue/node-role-based-authorization-api.git | ||
|
||
Pour lancer le backend | ||
- cd backend | ||
- npm i | ||
- npm run dev | ||
|
||
Pour lancer le frontend | ||
- cd frontend | ||
- npm i | ||
- npm run dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,39 @@ | ||
const jwt = require('express-jwt'); | ||
const { secret } = require('config.json'); | ||
const Role = require('./role'); | ||
const Permission = require('./permission'); | ||
|
||
module.exports = authorize; | ||
|
||
function authorize(roles = []) { | ||
// roles param can be a single role string (e.g. Role.User or 'User') | ||
// or an array of roles (e.g. [Role.Admin, Role.User] or ['Admin', 'User']) | ||
if (typeof roles === 'string') { | ||
roles = [roles]; | ||
} | ||
function authorize(permission) { | ||
|
||
return [ | ||
// authenticate JWT token and attach user to request object (req.user) | ||
jwt({ secret, algorithms: ['HS256'] }), | ||
|
||
// authorize based on user role | ||
(req, res, next) => { | ||
if (roles.length && !roles.includes(req.user.role)) { | ||
let isAuthorized = false | ||
if (permission === Permission.FREE_ACCESS) { | ||
// route without permission => allow every authenticated users | ||
isAuthorized = true | ||
} | ||
else if (req.user.role) { | ||
// retrieve permissions for role | ||
const role = Role[req.user.role] | ||
if (role && role.permissions.includes(permission)) { | ||
isAuthorized = true | ||
} | ||
} | ||
if (!isAuthorized) { | ||
// user's role is not authorized | ||
return res.status(401).json({ message: 'Unauthorized' }); | ||
} | ||
else { | ||
// authentication and authorization successful | ||
next(); | ||
} | ||
|
||
// authentication and authorization successful | ||
next(); | ||
} | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
LIST_USERS: "list_all_users", | ||
VIEW_PROFILE: "view_user_profile", | ||
FREE_ACCESS: "everybody" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,23 @@ | ||
const Permission = require("./permission") | ||
|
||
module.exports = { | ||
Admin: 'Admin', | ||
User: 'User' | ||
Admin: { | ||
name: "Admin", | ||
permissions: [ | ||
Permission.LIST_USERS, | ||
Permission.VIEW_PROFILE | ||
] | ||
}, | ||
User: { | ||
name: "User", | ||
permissions: [ | ||
Permission.VIEW_PROFILE | ||
] | ||
}, | ||
Guest: { | ||
name: "Guest", | ||
permissions: [ | ||
// nothing. Only FREE_ACCESS will be allowed for guests | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters