Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass csrf token on doi/manuscript fetch and clean up withCredentials #1281

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default class ApplicationAdapter extends JSONAPIAdapter {

get headers() {
return {
withCredentials: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markpatton withCredentials doesn't appear to be part of the fetch api. credentials is, but we are explicitly passing the csrf token here.

'X-XSRF-TOKEN': document.cookie.match(/XSRF-TOKEN\=([^;]*)/)['1'],
};
}
Expand Down
1 change: 0 additions & 1 deletion app/components/workflow-files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export default class WorkflowFiles extends Component {
async uploadFile(FileUpload) {
try {
const response = await FileUpload.upload(ENV.fileServicePath, {
withCredentials: true,
headers: {
'X-XSRF-TOKEN': document.cookie.match(/XSRF-TOKEN\=([^;]*)/)['1'],
},
Expand Down
1 change: 0 additions & 1 deletion app/services/doi.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default class DoiService extends Service {
let rawResponse = yield fetch(url, {
headers: {
Accept: 'application/json; charset=utf-8',
withCredentials: 'include',
'X-XSRF-TOKEN': document.cookie.match(/XSRF-TOKEN\=([^;]*)/)['1'],
},
});
Expand Down
8 changes: 7 additions & 1 deletion app/services/oa-manuscript-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ export default class OAManuscriptService extends Service {

const url = `${this.lookUpPath}?doi=${doi}`;

return fetch(url, { method: 'GET' })
return fetch(url, {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was missing the csrf token and was being spiked by the DOI service.

method: 'GET',
headers: {
Accept: 'application/json; charset=utf-8',
'X-XSRF-TOKEN': document.cookie.match(/XSRF-TOKEN\=([^;]*)/)['1'],
},
})
.then((resp) => {
if (resp.status !== 200) {
console.log(`%cFailed to lookup files for DOI (${doi}). Reason: "${resp.message}"`, 'color: red;');
Expand Down
Loading