Skip to content

Commit

Permalink
Use CSRF token on development
Browse files Browse the repository at this point in the history
Adds the 'yarn watch' command to rebuild the UI static files
whenever there is a change in the code. Running the Django
backend with './manage.py runserver' automatically collects
and serves the files with the CSRF token included.

Signed-off-by: Eva Millán <[email protected]>
  • Loading branch information
evamillan committed Jan 3, 2024
1 parent 7840f5f commit 43cc340
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 10 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ jobs:
uses: cypress-io/github-action@v5
with:
install: false
start: yarn serve --api_url=http://localhost:8000/api/
command: yarn test:e2e --config baseUrl=http://localhost:8080
wait-on: 'http://localhost:8080, http://localhost:8000/api/'
command: yarn test:e2e --config baseUrl=http://localhost:8000
wait-on: 'http://localhost:8000/api/'
spec: tests/e2e/specs/*.js
working-directory: ./ui
env:
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,16 @@ $ cd ui/
$ yarn install
```

#### Running the frontend
#### Running the frontend on development mode

Run SortingHat frontend Vue app:
Run SortingHat backend Django app:
```
(.venv)$ ./manage.py runserver --settings=config.settings.devel
```

Build the frontend and watch for changes:
```
$ yarn serve --api_url=http://localhost:8000/api/
$ yarn watch --api_url=http://localhost:8000/api/ --publicpath="/static/" --mode development
```


Expand Down
3 changes: 1 addition & 2 deletions config/settings/devel.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@
STATICFILES_DIRS = [
"./sortinghat/core/static",
]
STATIC_ROOT = "/tmp/static/"

STATIC_URL = '/'
STATIC_URL = '/static/'

MEDIA_URL = 'http://media.example.com/'

Expand Down
11 changes: 11 additions & 0 deletions releases/unreleased/csrf-token-only-required-from-ui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: CSRF token is only required on web requests
category: fixed
author: Eva Millán <evamillan@bitergia
issue: null
notes: >
The GraphQL API required the 'X-CSRFToken' header, but the
token could only be retrieved by making a GET request.
Now, requests authenticated using JWT don't need to provide the
CSRF token and only the user interface, which is vulnerable
to CSRF attacks and uses a different authentication, requires it.
4 changes: 4 additions & 0 deletions ui/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ module.exports = defineConfig({
specPattern: "tests/e2e/specs/**/*.cy.{js,jsx,ts,tsx}",
supportFile: "tests/e2e/support/index.js",
video: false,
retries: {
runMode: 2,
openMode: 0,
},
},
});
3 changes: 2 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"test:e2e": "cypress run --e2e",
"lint": "vue-cli-service lint",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
"build-storybook": "build-storybook",
"watch": "vue-cli-service build --watch"
},
"dependencies": {
"apollo-cache-inmemory": "^1.6.6",
Expand Down
2 changes: 1 addition & 1 deletion ui/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var path = require("path");
const { argv } = require("yargs");

module.exports = {
publicPath: process.env.NODE_ENV === "production" ? "/identities/" : "/",
publicPath: argv.publicpath ? argv.publicpath : process.env.NODE_ENV === "production" ? "/identities/" : "/",
outputDir: path.resolve(__dirname, "../sortinghat/", "core", "static"),
indexPath: path.resolve(
__dirname,
Expand Down

0 comments on commit 43cc340

Please sign in to comment.