diff --git a/console/src/components/Common/utils/sqlUtils.js b/console/src/components/Common/utils/sqlUtils.js new file mode 100644 index 0000000000000..10f432946f856 --- /dev/null +++ b/console/src/components/Common/utils/sqlUtils.js @@ -0,0 +1,9 @@ +export const sqlEscapeText = text => { + let _text = text; + + if (_text) { + _text = _text.replace(/'/g, "\\'"); + } + + return `E'${_text}'`; +}; diff --git a/console/src/components/Services/ApiExplorer/ApiRequest/ApiRequest.js b/console/src/components/Services/ApiExplorer/ApiRequest/ApiRequest.js index fa0a2fb275223..65da5b306d456 100644 --- a/console/src/components/Services/ApiExplorer/ApiRequest/ApiRequest.js +++ b/console/src/components/Services/ApiExplorer/ApiRequest/ApiRequest.js @@ -226,7 +226,7 @@ class ApiRequest extends Component { }; const getHeaderTable = () => { - const { headersSectionIsOpen } = this.state; + const { headersSectionIsOpen, adminSecretVisible } = this.state; const getHeaderRows = () => { const headers = this.props.headers; @@ -259,6 +259,9 @@ class ApiRequest extends Component { }; return headers.map((header, i) => { + const isAdminSecret = + header.key.toLowerCase() === `x-hasura-${globals.adminSecretLabel}`; + const getHeaderActiveCheckBox = () => { let headerActiveCheckbox = null; @@ -338,11 +341,7 @@ class ApiRequest extends Component { } let type = 'text'; - if ( - header.key.toLowerCase() === - `x-hasura-${globals.adminSecretLabel}` && - !this.state.adminSecretVisible - ) { + if (isAdminSecret && !adminSecretVisible) { type = 'password'; } @@ -368,10 +367,7 @@ class ApiRequest extends Component { const getHeaderAdminVal = () => { let headerAdminVal = null; - if ( - header.key.toLowerCase() === - `x-hasura-${globals.adminSecretLabel}` - ) { + if (isAdminSecret) { headerAdminVal = ( { tableName + '"' + ' IS ' + - "'" + - state.tableComment + - "';"; + sqlEscapeText(state.tableComment) + + ';'; } if (columnSpecificSql.length) { diff --git a/console/src/components/Services/Data/TableModify/ModifyActions.js b/console/src/components/Services/Data/TableModify/ModifyActions.js index 6096f4cd7efad..89bce11550fa2 100644 --- a/console/src/components/Services/Data/TableModify/ModifyActions.js +++ b/console/src/components/Services/Data/TableModify/ModifyActions.js @@ -27,6 +27,7 @@ import { } from '../Common/ReusableComponents/utils'; import { isPostgresFunction } from '../utils'; +import { sqlEscapeText } from '../../../Common/utils/sqlUtils'; import { fetchColumnCastsQuery, @@ -589,7 +590,7 @@ FOR EACH ${trigger.action_orientation} ${trigger.action_statement};`; if (trigger.comment) { downMigrationSql += `COMMENT ON TRIGGER "${triggerName}" ON "${tableSchema}"."${tableName}" -IS '${trigger.comment}';`; +IS ${sqlEscapeText(trigger.comment)};`; } const migrationDown = [ { @@ -1020,9 +1021,7 @@ const deleteColumnSql = (column, tableSchema) => { '"' + ' ' + 'IS ' + - "'" + - comment + - "'", + sqlEscapeText(comment), }, }); } @@ -1300,7 +1299,7 @@ const saveTableCommentSql = isTable => { const commentUpQuery = updatedComment === '' ? commentQueryBase + 'NULL' - : commentQueryBase + "'" + updatedComment + "'"; + : commentQueryBase + sqlEscapeText(updatedComment); const commentDownQuery = commentQueryBase + 'NULL'; const schemaChangesUp = [ @@ -1838,9 +1837,8 @@ const saveColumnChangesSql = (colName, column, onSuccess) => { colName + '"' + ' IS ' + - "'" + - comment + - "'"; + sqlEscapeText(comment); + const columnCommentDownQuery = 'COMMENT ON COLUMN ' + '"' + @@ -1855,9 +1853,7 @@ const saveColumnChangesSql = (colName, column, onSuccess) => { colName + '"' + ' IS ' + - "'" + - originalColComment + - "'"; + sqlEscapeText(originalColComment); // check if comment is unchanged and then do an update. if not skip if (originalColComment !== comment.trim()) { diff --git a/console/src/components/Services/Metadata/Actions.js b/console/src/components/Services/Metadata/Actions.js index 9c72f8f600cb8..2e58c54f46533 100644 --- a/console/src/components/Services/Metadata/Actions.js +++ b/console/src/components/Services/Metadata/Actions.js @@ -210,7 +210,11 @@ export const dropInconsistentObjects = () => { console.error(error); dispatch({ type: DROPPING_INCONSISTENT_METADATA_FAILED }); dispatch( - showErrorNotification('Dropping inconsistent metadata failed') + showErrorNotification( + 'Dropping inconsistent metadata failed', + null, + error + ) ); } ); @@ -531,7 +535,7 @@ export const metadataReducer = (state = defaultState, action) => { ...state, allowedQueries: [ ...state.allowedQueries.map(q => - (q.name === action.data.queryName ? action.data.newQuery : q) + q.name === action.data.queryName ? action.data.newQuery : q ), ], };