github-advanced-security[bot] commented on code in PR #2532: URL: https://github.com/apache/incubator-kie-tools/pull/2532#discussion_r1715296706
########## packages/sonataflow-mock-server/src/MockData/controllers.js: ########## @@ -0,0 +1,133 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +const path = require("path"); +const fs = require("fs"); +const formData = require("../MockData/forms/formData"); +const customDashboardData = require("../MockData/customDashboard/data"); +const { v4: uuidv4 } = require("uuid"); + +const formsUnableToSave = ["html_hiring_ITInterview", "react_hiring_ITInterview"]; + +module.exports = controller = { + getCustomDashboards: (req, res) => { + const filterNames = req.query.names.split(";"); + if (filterNames[0].length === 0) { + res.send(customDashboardData); + } else { + const filteredCustomDashboards = []; + filterNames.forEach((name) => { + customDashboardData.forEach((customDashboard) => { + if (customDashboard.name === name) { + filteredCustomDashboards.push(customDashboard); + } + }); + }); + res.send(filteredCustomDashboards); + } + }, + + getCustomDashboardContent: (req, res) => { + const dashboardName = req.params.name; + let content = ""; + if (dashboardName === "age.dash.yaml") { + content = fs.readFileSync(__dirname + "/customDashboard/age.dash.yaml", "utf-8"); + } + if (dashboardName === "products.dash.yaml") { + content = fs.readFileSync(__dirname + "/customDashboard/products.dash.yaml", "utf-8"); + } + res.send(content); + }, + + getForms: (req, res) => { + const formFilterNames = req.query.names.split(";"); + if (formFilterNames[0].length === 0) { + res.send(formData); + } else { + const filteredForms = []; + formFilterNames.forEach((name) => { + formData.forEach((form) => { + if (form.name === name) { + filteredForms.push(form); + } + }); + }); + res.send(filteredForms); + } + }, + + getFormContent: (req, res) => { + console.log(`......Get Custom Form Content: --formName:${req.params.formName}`); + const formName = req.params.formName; + const formInfo = formData.filter((datum) => datum.name === formName); + + if (formInfo.length === 0) { + res.status(500).send("Cannot find form"); + return; + } + let sourceString; + + const configString = fs.readFileSync(path.join(`${__dirname}/forms/examples/${formName}.config`), "utf8"); + if (formInfo[0].type.toLowerCase() === "html") { + sourceString = fs.readFileSync(path.join(`${__dirname}/forms/examples/${formName}.html`), "utf8"); Review Comment: ## Uncontrolled data used in path expression This path depends on a [user-provided value](1). [Show more details](https://github.com/apache/incubator-kie-tools/security/code-scanning/103) ########## packages/sonataflow-mock-server/src/MockData/controllers.js: ########## @@ -0,0 +1,133 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +const path = require("path"); +const fs = require("fs"); +const formData = require("../MockData/forms/formData"); +const customDashboardData = require("../MockData/customDashboard/data"); +const { v4: uuidv4 } = require("uuid"); + +const formsUnableToSave = ["html_hiring_ITInterview", "react_hiring_ITInterview"]; + +module.exports = controller = { + getCustomDashboards: (req, res) => { + const filterNames = req.query.names.split(";"); + if (filterNames[0].length === 0) { + res.send(customDashboardData); + } else { + const filteredCustomDashboards = []; + filterNames.forEach((name) => { + customDashboardData.forEach((customDashboard) => { + if (customDashboard.name === name) { + filteredCustomDashboards.push(customDashboard); + } + }); + }); + res.send(filteredCustomDashboards); + } + }, + + getCustomDashboardContent: (req, res) => { + const dashboardName = req.params.name; + let content = ""; + if (dashboardName === "age.dash.yaml") { + content = fs.readFileSync(__dirname + "/customDashboard/age.dash.yaml", "utf-8"); + } + if (dashboardName === "products.dash.yaml") { + content = fs.readFileSync(__dirname + "/customDashboard/products.dash.yaml", "utf-8"); + } + res.send(content); + }, + + getForms: (req, res) => { + const formFilterNames = req.query.names.split(";"); + if (formFilterNames[0].length === 0) { + res.send(formData); + } else { + const filteredForms = []; + formFilterNames.forEach((name) => { + formData.forEach((form) => { + if (form.name === name) { + filteredForms.push(form); + } + }); + }); + res.send(filteredForms); + } + }, + + getFormContent: (req, res) => { + console.log(`......Get Custom Form Content: --formName:${req.params.formName}`); + const formName = req.params.formName; + const formInfo = formData.filter((datum) => datum.name === formName); + + if (formInfo.length === 0) { + res.status(500).send("Cannot find form"); + return; + } + let sourceString; + + const configString = fs.readFileSync(path.join(`${__dirname}/forms/examples/${formName}.config`), "utf8"); Review Comment: ## Uncontrolled data used in path expression This path depends on a [user-provided value](1). [Show more details](https://github.com/apache/incubator-kie-tools/security/code-scanning/102) ########## packages/sonataflow-mock-server/src/MockData/controllers.js: ########## @@ -0,0 +1,133 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +const path = require("path"); +const fs = require("fs"); +const formData = require("../MockData/forms/formData"); +const customDashboardData = require("../MockData/customDashboard/data"); +const { v4: uuidv4 } = require("uuid"); + +const formsUnableToSave = ["html_hiring_ITInterview", "react_hiring_ITInterview"]; + +module.exports = controller = { + getCustomDashboards: (req, res) => { + const filterNames = req.query.names.split(";"); + if (filterNames[0].length === 0) { + res.send(customDashboardData); + } else { + const filteredCustomDashboards = []; + filterNames.forEach((name) => { + customDashboardData.forEach((customDashboard) => { + if (customDashboard.name === name) { + filteredCustomDashboards.push(customDashboard); + } + }); + }); + res.send(filteredCustomDashboards); + } + }, + + getCustomDashboardContent: (req, res) => { + const dashboardName = req.params.name; + let content = ""; + if (dashboardName === "age.dash.yaml") { + content = fs.readFileSync(__dirname + "/customDashboard/age.dash.yaml", "utf-8"); + } + if (dashboardName === "products.dash.yaml") { + content = fs.readFileSync(__dirname + "/customDashboard/products.dash.yaml", "utf-8"); + } + res.send(content); + }, + + getForms: (req, res) => { + const formFilterNames = req.query.names.split(";"); + if (formFilterNames[0].length === 0) { + res.send(formData); + } else { + const filteredForms = []; + formFilterNames.forEach((name) => { + formData.forEach((form) => { + if (form.name === name) { + filteredForms.push(form); + } + }); + }); + res.send(filteredForms); + } + }, + + getFormContent: (req, res) => { + console.log(`......Get Custom Form Content: --formName:${req.params.formName}`); + const formName = req.params.formName; + const formInfo = formData.filter((datum) => datum.name === formName); + + if (formInfo.length === 0) { + res.status(500).send("Cannot find form"); + return; + } + let sourceString; + + const configString = fs.readFileSync(path.join(`${__dirname}/forms/examples/${formName}.config`), "utf8"); + if (formInfo[0].type.toLowerCase() === "html") { + sourceString = fs.readFileSync(path.join(`${__dirname}/forms/examples/${formName}.html`), "utf8"); + } else if (formInfo[0].type.toLowerCase() === "tsx") { + sourceString = fs.readFileSync(path.join(`${__dirname}/forms/examples/${formName}.tsx`), "utf8"); + } + const response = { + formInfo: formInfo[0], + source: sourceString, + configuration: JSON.parse(configString), + }; + + res.send(response); + }, + + saveFormContent: (req, res) => { + console.log(`......Save Form Content: --formName:${req.params.formName}`); + if (formsUnableToSave.includes(req.params.formName)) { + res.status(500).send("Unexpected failure saving form!"); + } else { + res.send("Saved!"); + } + }, + + startProcessInstance: (_req, res) => { + res.send({ + id: uuidv4(), + }); + }, + + triggerCloudEvent: (req, res) => { + console.log( + `......Trigger Cloud Event:: id: ${req.headers["ce-id"]} type: ${req.headers["ce-type"]} source: ${req.headers["ce-source"]}` + ); + + if (req.body.type === "error") { + res.status(500).send("internal server error"); + } + if (req.body.kogitobusinesskey) { + console.log(`Starting Serverless workflow with business key: ${req.body.kogitobusinesskey}`); + return res.status(200).send(req.body.kogitobusinesskey); + } else if (req.body.kogitoprocrefid) { + console.log(`Serverless Workflow with id ${req.body.kogitoprocrefid} successfully completed`); + return res.status(200).send(req.body.kogitoprocrefid); Review Comment: ## Reflected cross-site scripting Cross-site scripting vulnerability due to a [user-provided value](1). [Show more details](https://github.com/apache/incubator-kie-tools/security/code-scanning/106) ########## packages/sonataflow-mock-server/src/server.js: ########## @@ -0,0 +1,202 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +// HTTP SERVER +const express = require("express"); +const swaggerUi = require("swagger-ui-express"); +const swaggerApiDoc = require("./MockData/openAPI/openapi.json"); +var cors = require("cors"); +const app = express(); +const { ApolloServer } = require("apollo-server-express"); +var bodyParser = require("body-parser"); +// GraphQL - Apollo +const { GraphQLScalarType } = require("graphql"); +const _ = require("lodash"); +// Config +const config = require("./config"); + +//Mock data +const data = require("./MockData/graphql"); +const controller = require("./MockData/controllers"); +const typeDefs = require("./MockData/types"); + +const DEFAULT_TIMEOUT = 2000; + +const swaggerOptions = { + swaggerOptions: { + url: "/q/openapi.json", + }, +}; + +function setPort(port = 4000) { + app.set("port", parseInt(port, 10)); +} + +function listen() { + const port = app.get("port") || config.port; + app.listen(port, () => { + console.log(`The server is running and listening at http://localhost:${port}`); + }); +} +// parse application/x-www-form-urlencoded +app.use(bodyParser.urlencoded({ extended: false })); + +// parse application/json +app.use(bodyParser.json()); +app.use( + cors({ + origin: config.corsDomain, // Be sure to switch to your production domain + optionsSuccessStatus: 200, + }) +); + +// handle empty GraphQL queries +app.use((req, res, next) => { + if (req.body && req.body.query === "") { + return res.status(200).send(); + } + next(); +}); + +app.post("/", controller.triggerCloudEvent); +app.put("/", controller.triggerCloudEvent); + +app.get("/q/openapi.json", (req, res) => res.json(swaggerApiDoc)); +app.use("/docs", swaggerUi.serveFiles(null, swaggerOptions), swaggerUi.setup(null, swaggerOptions)); + +app.get("/forms/list", controller.getForms); +app.get("/customDashboard/list", controller.getCustomDashboards); +app.get("/customDashboard/:name", controller.getCustomDashboardContent); Review Comment: ## Missing rate limiting This route handler performs [a file system access](1), but is not rate-limited. This route handler performs [a file system access](2), but is not rate-limited. [Show more details](https://github.com/apache/incubator-kie-tools/security/code-scanning/100) ########## packages/sonataflow-mock-server/src/MockData/controllers.js: ########## @@ -0,0 +1,133 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +const path = require("path"); +const fs = require("fs"); +const formData = require("../MockData/forms/formData"); +const customDashboardData = require("../MockData/customDashboard/data"); +const { v4: uuidv4 } = require("uuid"); + +const formsUnableToSave = ["html_hiring_ITInterview", "react_hiring_ITInterview"]; + +module.exports = controller = { + getCustomDashboards: (req, res) => { + const filterNames = req.query.names.split(";"); + if (filterNames[0].length === 0) { + res.send(customDashboardData); + } else { + const filteredCustomDashboards = []; + filterNames.forEach((name) => { + customDashboardData.forEach((customDashboard) => { + if (customDashboard.name === name) { + filteredCustomDashboards.push(customDashboard); + } + }); + }); + res.send(filteredCustomDashboards); + } + }, + + getCustomDashboardContent: (req, res) => { + const dashboardName = req.params.name; + let content = ""; + if (dashboardName === "age.dash.yaml") { + content = fs.readFileSync(__dirname + "/customDashboard/age.dash.yaml", "utf-8"); + } + if (dashboardName === "products.dash.yaml") { + content = fs.readFileSync(__dirname + "/customDashboard/products.dash.yaml", "utf-8"); + } + res.send(content); + }, + + getForms: (req, res) => { + const formFilterNames = req.query.names.split(";"); + if (formFilterNames[0].length === 0) { + res.send(formData); + } else { + const filteredForms = []; + formFilterNames.forEach((name) => { + formData.forEach((form) => { + if (form.name === name) { + filteredForms.push(form); + } + }); + }); + res.send(filteredForms); + } + }, + + getFormContent: (req, res) => { + console.log(`......Get Custom Form Content: --formName:${req.params.formName}`); + const formName = req.params.formName; + const formInfo = formData.filter((datum) => datum.name === formName); + + if (formInfo.length === 0) { + res.status(500).send("Cannot find form"); + return; + } + let sourceString; + + const configString = fs.readFileSync(path.join(`${__dirname}/forms/examples/${formName}.config`), "utf8"); + if (formInfo[0].type.toLowerCase() === "html") { + sourceString = fs.readFileSync(path.join(`${__dirname}/forms/examples/${formName}.html`), "utf8"); + } else if (formInfo[0].type.toLowerCase() === "tsx") { + sourceString = fs.readFileSync(path.join(`${__dirname}/forms/examples/${formName}.tsx`), "utf8"); Review Comment: ## Uncontrolled data used in path expression This path depends on a [user-provided value](1). [Show more details](https://github.com/apache/incubator-kie-tools/security/code-scanning/104) ########## packages/sonataflow-mock-server/src/server.js: ########## @@ -0,0 +1,202 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +// HTTP SERVER +const express = require("express"); +const swaggerUi = require("swagger-ui-express"); +const swaggerApiDoc = require("./MockData/openAPI/openapi.json"); +var cors = require("cors"); +const app = express(); +const { ApolloServer } = require("apollo-server-express"); +var bodyParser = require("body-parser"); +// GraphQL - Apollo +const { GraphQLScalarType } = require("graphql"); +const _ = require("lodash"); +// Config +const config = require("./config"); + +//Mock data +const data = require("./MockData/graphql"); +const controller = require("./MockData/controllers"); +const typeDefs = require("./MockData/types"); + +const DEFAULT_TIMEOUT = 2000; + +const swaggerOptions = { + swaggerOptions: { + url: "/q/openapi.json", + }, +}; + +function setPort(port = 4000) { + app.set("port", parseInt(port, 10)); +} + +function listen() { + const port = app.get("port") || config.port; + app.listen(port, () => { + console.log(`The server is running and listening at http://localhost:${port}`); + }); +} +// parse application/x-www-form-urlencoded +app.use(bodyParser.urlencoded({ extended: false })); + +// parse application/json +app.use(bodyParser.json()); +app.use( + cors({ + origin: config.corsDomain, // Be sure to switch to your production domain + optionsSuccessStatus: 200, + }) +); + +// handle empty GraphQL queries +app.use((req, res, next) => { + if (req.body && req.body.query === "") { + return res.status(200).send(); + } + next(); +}); + +app.post("/", controller.triggerCloudEvent); +app.put("/", controller.triggerCloudEvent); + +app.get("/q/openapi.json", (req, res) => res.json(swaggerApiDoc)); +app.use("/docs", swaggerUi.serveFiles(null, swaggerOptions), swaggerUi.setup(null, swaggerOptions)); + +app.get("/forms/list", controller.getForms); +app.get("/customDashboard/list", controller.getCustomDashboards); +app.get("/customDashboard/:name", controller.getCustomDashboardContent); +app.get("/forms/:formName", controller.getFormContent); Review Comment: ## Missing rate limiting This route handler performs [a file system access](1), but is not rate-limited. This route handler performs [a file system access](2), but is not rate-limited. This route handler performs [a file system access](3), but is not rate-limited. [Show more details](https://github.com/apache/incubator-kie-tools/security/code-scanning/101) ########## packages/sonataflow-mock-server/src/MockData/controllers.js: ########## @@ -0,0 +1,133 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +const path = require("path"); +const fs = require("fs"); +const formData = require("../MockData/forms/formData"); +const customDashboardData = require("../MockData/customDashboard/data"); +const { v4: uuidv4 } = require("uuid"); + +const formsUnableToSave = ["html_hiring_ITInterview", "react_hiring_ITInterview"]; + +module.exports = controller = { + getCustomDashboards: (req, res) => { + const filterNames = req.query.names.split(";"); + if (filterNames[0].length === 0) { + res.send(customDashboardData); + } else { + const filteredCustomDashboards = []; + filterNames.forEach((name) => { + customDashboardData.forEach((customDashboard) => { + if (customDashboard.name === name) { + filteredCustomDashboards.push(customDashboard); + } + }); + }); + res.send(filteredCustomDashboards); + } + }, + + getCustomDashboardContent: (req, res) => { + const dashboardName = req.params.name; + let content = ""; + if (dashboardName === "age.dash.yaml") { + content = fs.readFileSync(__dirname + "/customDashboard/age.dash.yaml", "utf-8"); + } + if (dashboardName === "products.dash.yaml") { + content = fs.readFileSync(__dirname + "/customDashboard/products.dash.yaml", "utf-8"); + } + res.send(content); + }, + + getForms: (req, res) => { + const formFilterNames = req.query.names.split(";"); + if (formFilterNames[0].length === 0) { + res.send(formData); + } else { + const filteredForms = []; + formFilterNames.forEach((name) => { + formData.forEach((form) => { + if (form.name === name) { + filteredForms.push(form); + } + }); + }); + res.send(filteredForms); + } + }, + + getFormContent: (req, res) => { + console.log(`......Get Custom Form Content: --formName:${req.params.formName}`); + const formName = req.params.formName; + const formInfo = formData.filter((datum) => datum.name === formName); + + if (formInfo.length === 0) { + res.status(500).send("Cannot find form"); + return; + } + let sourceString; + + const configString = fs.readFileSync(path.join(`${__dirname}/forms/examples/${formName}.config`), "utf8"); + if (formInfo[0].type.toLowerCase() === "html") { + sourceString = fs.readFileSync(path.join(`${__dirname}/forms/examples/${formName}.html`), "utf8"); + } else if (formInfo[0].type.toLowerCase() === "tsx") { + sourceString = fs.readFileSync(path.join(`${__dirname}/forms/examples/${formName}.tsx`), "utf8"); + } + const response = { + formInfo: formInfo[0], + source: sourceString, + configuration: JSON.parse(configString), + }; + + res.send(response); + }, + + saveFormContent: (req, res) => { + console.log(`......Save Form Content: --formName:${req.params.formName}`); + if (formsUnableToSave.includes(req.params.formName)) { + res.status(500).send("Unexpected failure saving form!"); + } else { + res.send("Saved!"); + } + }, + + startProcessInstance: (_req, res) => { + res.send({ + id: uuidv4(), + }); + }, + + triggerCloudEvent: (req, res) => { + console.log( + `......Trigger Cloud Event:: id: ${req.headers["ce-id"]} type: ${req.headers["ce-type"]} source: ${req.headers["ce-source"]}` + ); + + if (req.body.type === "error") { + res.status(500).send("internal server error"); + } + if (req.body.kogitobusinesskey) { + console.log(`Starting Serverless workflow with business key: ${req.body.kogitobusinesskey}`); + return res.status(200).send(req.body.kogitobusinesskey); Review Comment: ## Reflected cross-site scripting Cross-site scripting vulnerability due to a [user-provided value](1). [Show more details](https://github.com/apache/incubator-kie-tools/security/code-scanning/105) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
