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

PPS-588 guppy csrf #1464

Merged
merged 8 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
853 changes: 455 additions & 398 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@fortawesome/free-brands-svg-icons": "^5.14.0",
"@fortawesome/free-solid-svg-icons": "^5.2.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"@gen3/guppy": "^0.17.1",
"@gen3/guppy": "git+https://github.com/uc-cdis/guppy.git#8d2adb7370f63419d34585b24b64d1d875e5b1a7",
mfshao marked this conversation as resolved.
Show resolved Hide resolved
"@gen3/ui-component": "^0.11.4",
"@reactour/tour": "^2.12.0",
"@upsetjs/venn.js": "^1.4.2",
Expand Down
3 changes: 3 additions & 0 deletions src/GuppyDataExplorer/ExplorerFilter/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class ExplorerFilter extends React.Component {
accessibleFieldCheckList: this.props.accessibleFieldCheckList,
hideEmptyFilterSection: explorerHideEmptyFilterSection,
filterValuesToHide: explorerFilterValuesToHide,
csrfToken: this.props.csrfToken,
};
let filterFragment;
switch (this.state.selectedAccessFilter) {
Expand Down Expand Up @@ -215,6 +216,7 @@ ExplorerFilter.propTypes = {
unaccessibleFieldObject: PropTypes.object, // inherit from GuppyWrapper
adminAppliedPreFilters: PropTypes.object, // inherit from GuppyWrapper
accessibleFieldCheckList: PropTypes.arrayOf(PropTypes.string), // inherit from GuppyWrapper
csrfToken: PropTypes.string, // inherit from GuppyWrapper
getAccessButtonLink: PropTypes.string,
hideGetAccessButton: PropTypes.bool,
userFilterFromURL: PropTypes.object,
Expand All @@ -234,6 +236,7 @@ ExplorerFilter.defaultProps = {
unaccessibleFieldObject: {},
adminAppliedPreFilters: {},
accessibleFieldCheckList: [],
csrfToken: '',
getAccessButtonLink: undefined,
hideGetAccessButton: false,
userFilterFromURL: {},
Expand Down
2 changes: 2 additions & 0 deletions src/GuppyDataExplorer/GuppyDataExplorer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import GuppyWrapper from '@gen3/guppy/dist/components/GuppyWrapper';
import ExplorerVisualization from './ExplorerVisualization';
import ExplorerFilter from './ExplorerFilter';
import ExplorerTopMessageBanner from './ExplorerTopMessageBanner';
import { csrfToken } from '../configs';
import { labelToPlural, getQueryParameter, IsValidJSONString } from './utils';
import {
GuppyConfigType,
Expand Down Expand Up @@ -117,6 +118,7 @@ class GuppyDataExplorer extends React.Component {
onFilterChange={this.handleFilterChangeForQueryStateUrl}
rawDataFields={this.props.tableConfig.fields}
accessibleFieldCheckList={this.props.guppyConfig.accessibleFieldCheckList}
csrfToken={csrfToken}
>
<ExplorerTopMessageBanner
className='guppy-data-explorer__top-banner'
Expand Down
51 changes: 14 additions & 37 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,45 +206,22 @@ export const fetchWrapper = ({
// We first update the session so that the user will be notified
// if their auth is insufficient to perform the query.
export const fetchGraphQL = (graphQLParams) => sessionMonitor.updateSession()
.then(() => {
const request = {
credentials: 'include',
headers: { ...headers },
method: 'POST',
body: JSON.stringify(graphQLParams),
};

return fetch(graphqlPath, request)
.then((response) => response.text())
.then((responseBody) => {
try {
return JSON.parse(responseBody);
} catch (error) {
return responseBody;
}
});
});
.then(() => fetchWithCreds({ path: graphqlPath, body: JSON.stringify(graphQLParams), method: 'POST' })
.then((response) => {
if (response.status === 200 && response.data) {
return response.data;
}
return response;
}));

export const fetchFlatGraphQL = (graphQLParams) => sessionMonitor.updateSession()
.then(() => {
const request = {
credentials: 'include',
headers: { ...headers },
method: 'POST',
body: JSON.stringify(graphQLParams),
};

const graphqlUrl = guppyGraphQLUrl;
return fetch(graphqlUrl, request)
.then((response) => response.text())
.then((responseBody) => {
try {
return JSON.parse(responseBody);
} catch (error) {
return responseBody;
}
});
});
.then(() => fetchWithCreds({ path: guppyGraphQLUrl, body: JSON.stringify(graphQLParams), method: 'POST' })
.then((response) => {
if (response.status === 200 && response.data) {
return response.data;
}
return response;
}));

export const handleResponse = (type) => ({ data, status }) => {
switch (status) {
Expand Down
4 changes: 2 additions & 2 deletions src/configs.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { hostname } from './localconf';

export * from './localconf'; // / eslint-disable-line
const csrftoken = document.cookie.replace(/(?:(?:^|.*;\s*)csrftoken\s*=\s*([^;]*).*$)|^.*$/, '$1');
export const csrfToken = document.cookie.replace(/(?:(?:^|.*;\s*)csrftoken\s*=\s*([^;]*).*$)|^.*$/, '$1');

export const headers = {
Accept: 'application/json',
'Content-Type': 'application/json',
'x-csrf-token': csrftoken,
'x-csrf-token': csrfToken,
};

/**
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require('path');
const fs = require('fs');

const basename = process.env.BASENAME || '/';
const basenameWithTrailingSlash = basename.endsWith('/') ? basename : `${basename}/`;
const pathPrefix = basename.endsWith('/') ? basename.slice(0, basename.length - 1) : basename;
const app = process.env.APP || 'dev';

Expand Down Expand Up @@ -249,7 +250,7 @@ module.exports = {
output: {
path: __dirname,
filename: '[name].js',
publicPath: basename,
publicPath: basenameWithTrailingSlash,
},
optimization,
devtool,
Expand Down
Loading