Skip to content

Commit

Permalink
Make sure CSRF token is added to headers
Browse files Browse the repository at this point in the history
  • Loading branch information
markpatton committed Jun 3, 2024
1 parent b18c607 commit ffeb60e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
10 changes: 7 additions & 3 deletions app/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import JSONAPIAdapter from '@ember-data/adapter/json-api';
import { camelize } from '@ember/string';
import ENV from 'pass-ui/config/environment';
import { inject as service } from '@ember/service';
import { get } from '@ember/object';

/**
* PASS specific extensions for Ember Data's JSON:API adapter
Expand All @@ -11,9 +12,12 @@ export default class ApplicationAdapter extends JSONAPIAdapter {

namespace = ENV.passApi.namespace;

headers = {
withCredentials: true,
};
get headers() {
return {
withCredentials: true,
'X-XSRF-TOKEN': document.cookie.match(/XSRF-TOKEN\=([^;]*)/)['1'],
};
}

// Camel case instead of pluralize model types for our API
pathForType(type) {
Expand Down
4 changes: 4 additions & 0 deletions app/adapters/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default class FileAdapter extends ApplicationAdapter {
}
return fetch(url, {
method: 'DELETE',
credentials: 'same-origin',
headers: {
'X-XSRF-TOKEN': document.cookie.match(/XSRF-TOKEN\=([^;]*)/)['1'],
},
}).then((response) => {
if (!response.ok) {
throw new Error('Delete request to the file service failed');
Expand Down
7 changes: 6 additions & 1 deletion app/components/workflow-files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ export default class WorkflowFiles extends Component {
@action
async uploadFile(FileUpload) {
try {
const response = await FileUpload.upload(ENV.fileServicePath);
const response = await FileUpload.upload(ENV.fileServicePath, {
withCredentials: true,
headers: {
'X-XSRF-TOKEN': document.cookie.match(/XSRF-TOKEN\=([^;]*)/)['1'],
},
});

const file = await response.json();

Expand Down

0 comments on commit ffeb60e

Please sign in to comment.