diff --git a/sdarq/backend/src/app.py b/sdarq/backend/src/app.py index 928fa8903..a2f22667f 100644 --- a/sdarq/backend/src/app.py +++ b/sdarq/backend/src/app.py @@ -693,6 +693,61 @@ def edit_sec_controls(): return jsonify({'statusText': message}), 400 +@app.route('/delete_service_sec_controls/', methods=['POST']) +@cross_origin(origins=sdarq_host) +def delete_service_sec_controls(): + """ + Delete security controls for a service + Args: Provided json data from user + Returns: 200 status if data remove successfully + 404 if service not found + 400 is there is an error + """ + json_data = request.get_json() + service_name = json_data['service'] + pattern = "^[a-zA-Z0-9][a-zA-Z0-9-_ ]{1,28}[a-zA-Z0-9]$" + user_email = request.headers.get('X-Goog-Authenticated-User-Email') + + if request.headers.get('Content-Type') != 'application/json': + return jsonify({'statusText': 'Bad Request'}), 400 + + if re.match(pattern, service_name): + try: + validate(instance=json_data, schema=edit_security_controls_schema) + doc_ref = db.collection(security_controls_firestore_collection).document( + service_name.lower()) + doc = doc_ref.get() + if bool(doc.to_dict()) is True: + db.collection(security_controls_firestore_collection).document(service_name.lower()).delete() + logging.info("Security control %s for the choosen service are removed by %s !", + service_name, user_email) + return '' + else: + message = """ + This service does not exist! + """ + logging.info( + "User %s requested to remove service security controls, but this service does not exist!", + user_email) + return jsonify({'statusText': message}), 404 + except Exception as error: + error_message = f"Exception /delete_service_sec_controls endpoint: {error}" + slacknotify.slacknotify_error_endpoint(error_message, appsec_sdarq_error_channel, user_email) + logging.warning(error_message) + message = """ + There is something wrong with the input! Server did not respond correctly to your request! + """ + return jsonify({'statusText': message}), 400 + else: + message = """ + Invalid input! Please make sure you include numbers, -, _ and alphabetical characters. + """ + logging.info( + "User %s requested to remove Security Controls for a service, but INVALID input was provided", + user_email) + return jsonify({'statusText': message}), 400 + + @app.route('/get_sec_controls/', methods=['GET']) @cross_origin(origins=sdarq_host) def get_sec_controls(): diff --git a/sdarq/backend/src/schemas/edit_security_controls_schema.py b/sdarq/backend/src/schemas/edit_security_controls_schema.py index dbc32710b..c77aced8e 100644 --- a/sdarq/backend/src/schemas/edit_security_controls_schema.py +++ b/sdarq/backend/src/schemas/edit_security_controls_schema.py @@ -13,7 +13,7 @@ }, "github": { "type": "string", - "pattern": "^(https:\/\/github\.com\/[a-zA-Z0-9-]+\/[a-zA-Z0-9-]+|(N\/A))$" + "pattern": "^(https://github.com/[a-zA-Z0-9-]+/[a-zA-Z0-9-]+|(N/A))$" }, "threat_model": { "type": "boolean", diff --git a/sdarq/backend/src/schemas/new_service_schema.py b/sdarq/backend/src/schemas/new_service_schema.py index b3b4dddf3..4237402be 100644 --- a/sdarq/backend/src/schemas/new_service_schema.py +++ b/sdarq/backend/src/schemas/new_service_schema.py @@ -21,7 +21,7 @@ }, "Github URL": { "type": "string", - "pattern": "^(https:\/\/github\.com\/[a-zA-Z0-9-]+\/[a-zA-Z0-9-]+|(N\/A))$" + "pattern": "^(https://github.com/[a-zA-Z0-9-]+/[a-zA-Z0-9-]+|(N/A))$" }, "Architecture Diagram": { "type": "string", diff --git a/sdarq/backend/src/schemas/security_controls_schema.py b/sdarq/backend/src/schemas/security_controls_schema.py index 95bcbf88a..63eac50d3 100644 --- a/sdarq/backend/src/schemas/security_controls_schema.py +++ b/sdarq/backend/src/schemas/security_controls_schema.py @@ -13,7 +13,7 @@ }, "github": { "type": "string", - "pattern": "^(https:\/\/github\.com\/[a-zA-Z0-9-]+\/[a-zA-Z0-9-]+|(N\/A))$" + "pattern": "^(https://github.com/[a-zA-Z0-9-]+/[a-zA-Z0-9-]+|(N/A))$" }, "dev_url": { "type": "string", diff --git a/sdarq/backend/src/schemas/threat_model_request_schema.py b/sdarq/backend/src/schemas/threat_model_request_schema.py index 05d76498f..125bad0d1 100644 --- a/sdarq/backend/src/schemas/threat_model_request_schema.py +++ b/sdarq/backend/src/schemas/threat_model_request_schema.py @@ -5,7 +5,7 @@ "properties": { "Type": { "type": "string", - "pattern": "^[a-zA-Z0-9][a-zA-Z0-9\\s]{1,30}[a-zA-Z0-9\s]$" + "pattern": "^[a-zA-Z0-9][a-zA-Z0-9\s]{1,30}[a-zA-Z0-9\s]$" }, "Name": { "type": "string", diff --git a/sdarq/frontend/src/app/app-routing.module.ts b/sdarq/frontend/src/app/app-routing.module.ts index 898110f28..2228c0da2 100644 --- a/sdarq/frontend/src/app/app-routing.module.ts +++ b/sdarq/frontend/src/app/app-routing.module.ts @@ -22,6 +22,7 @@ import { AppFormComponent } from './app-form/app-form.component'; import { AppsMainpageComponent } from './apps-mainpage/apps-mainpage.component'; import { ServiceSecurityControlsComponent } from './service-security-controls/service-security-controls.component'; import { SearchServiceSecurityControlsComponent } from './search-service-security-controls/search-service-security-controls.component'; +import { DeleteServiceSecurityControlsComponent } from './delete-service-security-controls/delete-service-security-controls.component'; const routes: Routes = [ @@ -46,6 +47,7 @@ const routes: Routes = [ { path: 'security-pentest/request', component: SecurityPentestComponent }, { path: 'service-security-controls/results', component: ServiceSecurityControlsComponent }, { path: 'search-service-security-controls', component: SearchServiceSecurityControlsComponent }, + { path: 'security-control/delete-service', component: DeleteServiceSecurityControlsComponent }, { path: '404', component: NotfoundComponent }, { path: '**', redirectTo: '/404' } ]; diff --git a/sdarq/frontend/src/app/app.module.ts b/sdarq/frontend/src/app/app.module.ts index 468a9b982..46a1defb0 100644 --- a/sdarq/frontend/src/app/app.module.ts +++ b/sdarq/frontend/src/app/app.module.ts @@ -47,6 +47,8 @@ import { AppFormComponent } from './app-form/app-form.component'; import { AppsMainpageComponent } from './apps-mainpage/apps-mainpage.component'; import { ServiceSecurityControlsComponent } from './service-security-controls/service-security-controls.component'; import { SearchServiceSecurityControlsComponent } from './search-service-security-controls/search-service-security-controls.component'; +import { DeleteServiceSecurityControlsComponent } from './delete-service-security-controls/delete-service-security-controls.component'; +import { DeleteServiceSecurityControlsService } from './services/delete-service-security-controls/delete-service-security-controls.service'; @NgModule({ @@ -79,10 +81,11 @@ import { SearchServiceSecurityControlsComponent } from './search-service-securit AppFormComponent, AppsMainpageComponent, ServiceSecurityControlsComponent, - SearchServiceSecurityControlsComponent + SearchServiceSecurityControlsComponent, + DeleteServiceSecurityControlsComponent ], imports: [ - BrowserModule, + BrowserModule, FormsModule, HttpClientModule, AppRoutingModule, @@ -103,7 +106,8 @@ import { SearchServiceSecurityControlsComponent } from './search-service-securit GetServiceSecurityControlsService, RequestSecurityPentestService, JiraTicketRiskAssessmentService, - SendAppFormDataService + SendAppFormDataService, + DeleteServiceSecurityControlsService ], bootstrap: [ AppComponent diff --git a/sdarq/frontend/src/app/delete-service-security-controls/delete-service-security-controls.component.css b/sdarq/frontend/src/app/delete-service-security-controls/delete-service-security-controls.component.css new file mode 100644 index 000000000..e69de29bb diff --git a/sdarq/frontend/src/app/delete-service-security-controls/delete-service-security-controls.component.html b/sdarq/frontend/src/app/delete-service-security-controls/delete-service-security-controls.component.html new file mode 100644 index 000000000..78f5c3429 --- /dev/null +++ b/sdarq/frontend/src/app/delete-service-security-controls/delete-service-security-controls.component.html @@ -0,0 +1,14 @@ +
{{error_message}}
+Please contact AppSec team for more information!
+