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

[ResponseOps][Connectors] Possible to open close incident in ServiceNow #184646

Closed
cnasikas opened this issue Jun 3, 2024 · 1 comment · Fixed by #199989
Closed

[ResponseOps][Connectors] Possible to open close incident in ServiceNow #184646

cnasikas opened this issue Jun 3, 2024 · 1 comment · Fixed by #199989
Assignees
Labels
appex-ro-mx-team-member-onboarding bug Fixes for quality problems that affect the customer experience Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)

Comments

@cnasikas
Copy link
Member

cnasikas commented Jun 3, 2024

We got an SDH where it was possible to create new issues in ServiceNow with the state as closed due to race conditions. Taking a look at the following code

const { correlationId, incidentId } = params;
      let incidentToBeClosed = null;

      if (correlationId == null && incidentId == null) {
        throw new Error('No correlationId or incidentId found.');
      }

      if (incidentId) {
        incidentToBeClosed = await getIncident(incidentId);
      } else if (correlationId) {
        incidentToBeClosed = await getIncidentByCorrelationId(correlationId);
      }

      if (incidentToBeClosed === null) {
        logger.warn(
          `[ServiceNow][CloseIncident] No incident found with correlation_id: ${correlationId} or incidentId: ${incidentId}.`
        );

        return null;
      }

      if (incidentToBeClosed.state === '7') {
        logger.warn(
          `[ServiceNow][CloseIncident] Incident with correlation_id: ${correlationId} or incidentId: ${incidentId} is closed.`
        );

        return {
          title: incidentToBeClosed.number,
          id: incidentToBeClosed.sys_id,
          pushedDate: getPushedDate(incidentToBeClosed.sys_updated_on),
          url: getIncidentViewURL(incidentToBeClosed.sys_id),
        };
      }

      const closedIncident = await updateIncident({
        incidentId: incidentToBeClosed.sys_id,
        incident: {
          state: '7', // used for "closed" status in serviceNow
          close_code: 'Closed/Resolved by Caller',
          close_notes: 'Closed by Caller',
        },
      });

      return closedIncident;

we can see that for this to happen the incidentToBeClosed === null checks need to be bypassed so the await updateIncident({...}) can be called. This is possible only if getIncident or getIncidentByCorrelationId returns {}. This is possible if the user does not have permission on all records of the incident table (ServiceNow will return an empty object in this case). A possible fix would be to do the check as incidentToBeClosed == null || isEmpty(incidentToBeClosed) || isEmpty(incidentToBeClosed.sys_id).

@cnasikas cnasikas added bug Fixes for quality problems that affect the customer experience Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) labels Jun 3, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@heespi heespi added appex-ro-mx-team-member-onboarding and removed Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) labels Sep 20, 2024
@botelastic botelastic bot added the needs-team Issues missing a team label label Sep 20, 2024
@cnasikas cnasikas added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) and removed needs-team Issues missing a team label labels Sep 21, 2024
georgianaonoleata1904 added a commit that referenced this issue Nov 19, 2024
#199989)

Closes #184646

## Summary

- updated the code to include additional validation, ensuring that
updateIncident({...}) is not called when incidentToBeClosed object is
empty, this ensured that cases where getIncident or
getIncidentByCorrelationId return an empty object are properly handled.

- small change in Run connector flyout > configuration tab: fixed typo,
"read-only" instead of "readonly"
kibanamachine pushed a commit to kibanamachine/kibana that referenced this issue Nov 19, 2024
elastic#199989)

Closes elastic#184646

## Summary

- updated the code to include additional validation, ensuring that
updateIncident({...}) is not called when incidentToBeClosed object is
empty, this ensured that cases where getIncident or
getIncidentByCorrelationId return an empty object are properly handled.

- small change in Run connector flyout > configuration tab: fixed typo,
"read-only" instead of "readonly"

(cherry picked from commit 5d77a1a)
paulinashakirova pushed a commit to paulinashakirova/kibana that referenced this issue Nov 26, 2024
elastic#199989)

Closes elastic#184646

## Summary

- updated the code to include additional validation, ensuring that
updateIncident({...}) is not called when incidentToBeClosed object is
empty, this ensured that cases where getIncident or
getIncidentByCorrelationId return an empty object are properly handled.

- small change in Run connector flyout > configuration tab: fixed typo,
"read-only" instead of "readonly"
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this issue Dec 12, 2024
elastic#199989)

Closes elastic#184646

## Summary

- updated the code to include additional validation, ensuring that
updateIncident({...}) is not called when incidentToBeClosed object is
empty, this ensured that cases where getIncident or
getIncidentByCorrelationId return an empty object are properly handled.

- small change in Run connector flyout > configuration tab: fixed typo,
"read-only" instead of "readonly"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appex-ro-mx-team-member-onboarding bug Fixes for quality problems that affect the customer experience Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants