diff --git a/README.md b/README.md
index 8b137891..6886588e 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,172 @@
+# open-appsec NPM Proxy Manager integration (beta)
+This is the repository for the beta release of the new integration of open-appsec WAF with NGINX Proxy Manager.
+This will allow NGINX Proxy Manager (NPM) users to protect their web applications and web APIs exposed by NGINX Proxy Manager by easily activating and configuring open-appsec protection for each of the configured Proxy Host objects in NPM directly from the NPM Web UI and also to monitor security events.
+This new integration of open-appsec WAF with NGINX Proxy Manager not only closes the security gap caused by the soon end-of-life ModSecurity WAF, but provides a modern, strong protection alternative in form of open-appsec, a preemptive, machine-learning based, fully automatic WAF that does not rely on signatures at all.
+
+### NGINX Proxy Manager
+Nginx Proxy Manager is a popular open-source project that simplifies the management of NGINX reverse proxy configurations, offering a user-friendly web-based interface for easy setup and maintenance. It was created by “jc21” (https://www.jc21.com).
+This project is particularly useful for individuals and organizations looking to streamline the deployment of web applications and services by efficiently managing multiple domains and subdomains through a centralized interface.
+With NGINX Proxy Manager, users can effortlessly create and manage SSL certificates, enabling secure HTTPS connections for their applications, while also providing advanced features such as Let's Encrypt integration for automated certificate renewal.
+NGINX Proxy Manager (NPM) is based on NGINX and provided as a container image that can be easily deployed in containerized environments like Docker (typically using Docker Compose) or others.
+NPM itself does not include any WAF solution for effective Threat Prevention against modern attacks or Zero-day attacks.
+
+Website and Docs: https://nginxproxymanager.com
+Github: https://github.com/NginxProxyManager
+
+### open-appsec WAF:
+
+open-appsec WAF provides automatic, preemptive threat prevention for reverse proxies like NGINX. It is machine learning based, which means it doesn’t require signatures (or updating them) at all. This enables it to provide state-of-the-art threat prevention even for true zero-day attacks while significantly reducing both, administrative effort as well as the amount of false-positives.
+open-appsec therefore is a great fit to provide advanced threat prevention to the services exposed by NGINX Proxy Manager.
+
+Website: https://www.openappsec.io
+Github: https://github.com/openappsec
+Docs: https://docs.openappsec.io
+
+### Integration of open-appsec WAF with NGINX Proxy Manager:
+
+With this integration we are focusing on maximum simplicity for the user to maintain the low entry barrier as a key design principle of the NGINX proxy manager (NPM) project, which we want in the same way to apply also to the addition of open-appsec.
+
+The actual deployment of NPM with open-appsec is performed using a slightly enhanced docker compose file (see below) which also adds the open-appsec agent container to it, which will perform the actual security inspection.
+The NGINX proxy manager container deployed as part of the docker compose is using the “open-appsec-npm” image, provided by the open-appsec team, which is based on the regular NPM code but also adds the open-appsec attachment to it as an NGINX module. This attachment enables the connection between the NGINX and the open-appsec agent and provides the HTTP data for inspection to the Agent.
+The “open-appsec-npm” container also contains various NPM WebUI enhancements and the integration logic allowing the configuration, administration and monitoring of open-appsec.
+
+You can read more about open-appsec’s Technology here:
+https://www.openappsec.io/tech
+
+After successful deployment you can then activate and configure open-appsec directly from the enhanced NPM Web UI interface to which the most relevant configuration options for the open-appsec WAF as well as an option to view the open-appsec logs have been added.
+
+The resulting architecture with the open-appsec Agent container and the NGINX Proxy Manager container then looks like this:
+
+
+
+Documentation: https://docs.openappsec.io/integrations/nginx-proxy-manager-integration
+
+# Deployment Step-by-Step:
+Before you start, make sure to have a Linux environment with Docker and Docker Compose suitable with version 3.8 available.
+To deploy NGINX Proxy Manager with open-appsec integration follow the steps below:
+1. Within the directory which you want to use for the deployment:
+Create a folder appsec-localconfig which will hold the appsec declarative configuration file (this will be managed by the enhanced NPM WebUI)
+```
+mkdir ./appsec-localconfig
+```
+2. Download the initial declarative configuration file for open-appsec into that folder.
+This will be managed from the NPM WebUI.
+```
+wget https://raw.githubusercontent.com/openappsec/open-appsec-npm/main/deployment/local_policy.yaml -O ./appsec-localconfig/local_policy.yaml
+```
+3. Create a docker-compose.yaml file with the content below, it can be downloaded as follows:
+```
+wget https://raw.githubusercontent.com/openappsec/open-appsec-npm/main/deployment/docker-compose.yaml
+```
+4. Run docker-compose up to start the deployment of all relevant containers:
+```
+docker-compose up -d
+```
+5. Check if the nginx-proxy-manager-attachment and the appsec-agent containers are up and running:
+```
+docker ps
+```
+Congratulations, now you are all set and you can login with your web browser to the WebUI of NGINX Proxy Manager with open-appsec integration as follows:
+```
+http://[hostname or IP of your host]:81
+```
+
+
+
+At first login please use the following default administrator user credentials:
+
+E-mail address: admin@example.com
+Password: changeme
+
+You will then be prompted to provide your own user details and asked to change the password, before being presented with the NGINX Proxy Manager Dashboard view:
+
+
+
+# Configuration
+To learn how to use NGINX Proxy Manager (NPM) please see project documentation, as NPM usage and configuration will not be explained here:
+https://nginx-proxy-manager.com
+
+Once you created a new Proxy Host within NGINX Proxy Manager WebUI you can now easily enable and configure open-appsec protection (see also screenshot below):
+1. Enable open-appsec by flipping the “open-appsec” switch to enabled.
+2. Select the Enforcement Mode, it can be either “Prevent-Learn” or “Detect-Learn”
+3. Select the minimum confidence level for open-appsec to prevent an attack (only relevant when in prevent mode), it can be either “Critical”, “High” or “Medium” confidence.
+4. Click “Save”
+
+
+
+This screenshot for example shows a “Proxy Host” reverse proxy configuration in NPM that will listen to inbound traffic for hostnames “100.25.161.101”, “localhost” or “my.webserver.com”.
+This “Proxy Host” has open-appsec enabled in “Prevent-Learn” mode and therefore will prevent incoming http or https requests when there’s a minimum confidence level of “High” or higher, as configured for the “Minimum confidence for prevent” setting.
+Non-malicious traffic will then be proxied using “http” protocol to the configured backend webserver with the IP address “192.168.160.2” on port “80”.
+
+Note: Changes in the open-appsec configuration performed and saved in the NPM Web UI can take up to 30 seconds before they become effective.
+
+This was just a very basic overview to get you started, there's many more things you can configure as part of the open-appsec NGINX Proxy Manager integration.
+
+If you want to check out the open-appsec Security Logs click on the new menu option “Security Log” which allows you to view the open-appsec specific logs directly from the NPM Web UI:
+
+
+**You find the full documentation including FAQ here:
+https://docs.openappsec.io/integrations/nginx-proxy-manager-integration/**
+
+# Compilation Instructions
+
+**Important: In order to deploy and use the open-appsec NGINX Proxy Manager integration you do not have to compile the code yourself.**
+We offer a pre-compiled ready-to-use "open-appsec-npm" container (see above in the "Deployment" section).
+
+## Prerequisites
+- Linux Machine with Docker engine deployed
+
+## Additional perquisites for compiling against other NGINX Proxy Manager version
+Precompiled libraries for open-appsec Attachment for the specific version of NGINX Proxy Manager you want to compile agasint.
+You find the detailed compilation instructions in this repo: https://github.com/openappsec/attachment
+
+Make sure to compile the attachment using a container with the exact same OS version as used in the NPM container version you want to build the integration upon and provide also the NGINX version information from that container.
+libngx_module.so libosrc_compression_utils.so libosrc_nginx_attachment_util.so libosrc_shmem_ipc.so
+
+## Preparations
+Clone this repository to your local Linux machine:
+```
+git clone https://github.com/openappsec/open-appsec-npm.git
+```
+
+Change into the open-appsec-npm directory:
+```
+cd open-appsec-npm
+```
+### If you are compiling against other NGINX proxy Manager version
+Replace the files in the ```docker/lib``` folder with the libraries you've precompiled.
+
+Compilation - Build the Frontend:
+---
+```
+cd scripts/ci
+bash frontend-build
+```
+
+Build the open-appsec-npm Container Image:
+--
+```
+cd ../..
+docker buildx build --load -t open-appsec-npm -f docker/Dockerfile .
+```
+
+**Congratulations, you have successfully built your own open-appsec-npm container.**
+You can deploy it now by specifying it within the docker-compose.yaml file.
+You find the deployment instructions above in the "Deployment" section.
+If you also want to build your own open-appsec Agent container you find the instructions in this repo:
+https://github.com/openappsec/openappsec
+
+# Contributing
+We welcome everyone that wishes to share their knowledge and expertise to enhance and expand this project.
+
+Please see the [Contributing Guidelines](https://github.com/openappsec/openappsec-npm/blob/main/CONTRIBUTING.md).
+
+# Final notes
+
+We hope this integration will be useful for you and provide you easy-to-configure yet highly effective protection based on open-appsec for your web services or web APIs against known and especially unknown, zero day attacks!
+
+If you have any questions, feedback or need assistance with some issue you can
+- contact us at info@openappsec.io
+- contact us using the chat on our project website https://www.openappsec.io
+- open an issue in the GitHub project
diff --git a/backend/internal/nginx-openappsec.js b/backend/internal/nginx-openappsec.js
new file mode 100755
index 00000000..c29a38a9
--- /dev/null
+++ b/backend/internal/nginx-openappsec.js
@@ -0,0 +1,314 @@
+const util = require('util');
+const execPromise = util.promisify(require('child_process').exec);
+const { exec } = require('child_process');
+const _ = require('lodash');
+const fs = require('fs');
+const logger = require('../logger').nginx;
+const config = require('../lib/config');
+const yaml = require('js-yaml');
+const path = require('path');
+const constants = require('../lib/constants');
+
+const internalNginxOpenappsec = {
+
+ // module constants
+ CONFIG_TEMPLATE_FILE_NAME: 'local-policy-open-appsec-enabled-for-proxy-host.yaml',
+ CONFIG_TEMPLATE_DIR: '/app/templates',
+
+ // module variables
+ config: null,
+ configTemplate: null,
+
+ /**
+ * Generate an open-appsec config file for a proxy host.
+ *
+ * @param {Object} access
+ * @param {Object} row
+ * @param {Object} data
+ * @returns {Promise}
+ */
+ generateConfig: (access, row, data) => {
+ return access.can('settings:update', row.id)
+ .then(() => {
+ if (config.debug()) {
+ logger.info('Generating openappsec config:', JSON.stringify(data, null, 2));
+ }
+
+ const openappsecMode = data.use_openappsec == false ? 'inactive' : data.openappsec_mode;
+
+ const configTemplateFilePath = path.join(internalNginxOpenappsec.CONFIG_TEMPLATE_DIR, internalNginxOpenappsec.CONFIG_TEMPLATE_FILE_NAME)
+ const configFilePath = path.join(constants.APPSEC_EXT_DIR, constants.APPSEC_CONFIG_FILE_NAME);
+
+ let openappsecConfig = yaml.load(fs.readFileSync(configFilePath, 'utf8'));
+ let openappsecConfigTemplate = yaml.load(fs.readFileSync(configTemplateFilePath, 'utf8'));
+
+ internalNginxOpenappsec.config = openappsecConfig;
+ internalNginxOpenappsec.configTemplate = openappsecConfigTemplate;
+
+ const specificRuleName = 'npm-managed-specific-rule-proxyhost-' + row.id;
+ const logTriggerName = 'npm-managed-log-trigger-proxyhost-' + row.id;
+ const practiceName = 'npm-managed-practice-proxyhost-' + row.id;
+
+ _.remove(openappsecConfig.policies['specific-rules'], rule => rule.name === specificRuleName || rule.name.startsWith(`${specificRuleName}.`));
+
+ data.domain_names.forEach((domain, index) => {
+ let ruleName = index > 0 ? `${specificRuleName}.${index}` : specificRuleName;
+ let specificRuleNode = {
+ host: domain,
+ name: ruleName,
+ triggers: [logTriggerName],
+ mode: openappsecMode,
+ practices: [practiceName]
+ };
+ internalNginxOpenappsec.updateNode('policies', 'specific-rules', specificRuleNode, openappsecMode);
+ });
+
+ internalNginxOpenappsec.updateNode('', 'practices', { name: practiceName, 'web-attacks.override-mode': openappsecMode, 'web-attacks.minimum-confidence': data.minimum_confidence }, openappsecMode);
+ internalNginxOpenappsec.updateNode('', 'log-triggers', { name: logTriggerName }, openappsecMode);
+
+ // remove all openappsec managed location config nodes for a proxy host.
+ let pattern = new RegExp(`^npm-managed.*-${row.id}-.*`);
+ internalNginxOpenappsec.removeMatchingNodes(openappsecConfig, pattern);
+
+ // for each data.location, create location config nodes
+ data.locations.forEach((location, index) => {
+ let locationSpecificRuleName = 'npm-managed-specific-rule-proxyhost-' + row.id + '-' + index;
+ let locationLogTriggerName = 'npm-managed-log-trigger-proxyhost-' + row.id + '-' + index;
+ let locationPracticeName = 'npm-managed-practice-proxyhost-' + row.id + '-' + index;
+
+ let locationOpenappsecMode = location.use_openappsec == false ? 'inactive' : location.openappsec_mode;
+
+ _.remove(openappsecConfig.policies['specific-rules'], rule => rule.name === locationSpecificRuleName || rule.name.startsWith(`${locationSpecificRuleName}.`));
+
+ data.domain_names.forEach((domain, index) => {
+ let locationUrl = domain + location.path;
+ let ruleName = index > 0 ? `${locationSpecificRuleName}.${index}` : locationSpecificRuleName;
+
+ let domainSpecificRuleNode = {
+ host: locationUrl,
+ name: ruleName,
+ triggers: [locationLogTriggerName],
+ mode: locationOpenappsecMode,
+ practices: [locationPracticeName]
+ };
+ internalNginxOpenappsec.updateNode('policies', 'specific-rules', domainSpecificRuleNode, locationOpenappsecMode, 'location', openappsecMode);
+ });
+
+ internalNginxOpenappsec.updateNode('', 'practices', { name: locationPracticeName, 'web-attacks.override-mode': locationOpenappsecMode, 'web-attacks.minimum-confidence': location.minimum_confidence }, locationOpenappsecMode, 'location', openappsecMode);
+ internalNginxOpenappsec.updateNode('', 'log-triggers', { name: locationLogTriggerName }, locationOpenappsecMode, 'location', openappsecMode);
+ });
+
+ fs.writeFileSync(configFilePath, yaml.dump(openappsecConfig));
+ },
+ (err) => {
+ logger.error('Error generating openappsec config:', err);
+ return Promise.reject(err);
+ })
+ .then(() => {
+ // Return the notifyPolicyUpdate promise chain
+ // notify openappsec to apply the policy
+ return internalNginxOpenappsec.notifyPolicyUpdate().catch((errorMessage) => {
+ // console.error('Error:', errorMessage);
+ const errorMessageForUI = `Error: Policy couldn’t be applied, open-appsec-agent container is not responding.
+ Check if open-appec-agent container is running, then apply open-appsec Configuration
+ again by clicking here:
+
Settings -> open-appsec Advanced -> Save Settings`;
+
+ return Promise.reject(new Error(errorMessageForUI));
+ });
+ });
+ },
+
+ /**
+ * Remove all openappsec managed config nodes for a proxy host.
+ *
+ * @param {Object} access
+ * @param {Object} row
+ * @returns {Promise}
+ *
+ */
+ deleteConfig: (access, row) => {
+ return access.can('settings:update', row.id)
+ .then(() => {
+ const configFilePath = path.join(constants.APPSEC_EXT_DIR, constants.APPSEC_CONFIG_FILE_NAME);
+ let openappsecConfig = yaml.load(fs.readFileSync(configFilePath, 'utf8'));
+
+ // remove all openappsec managed location config nodes for a proxy host.
+ let pattern = new RegExp(`^npm-managed.*-${row.id}`);
+ internalNginxOpenappsec.removeMatchingNodes(openappsecConfig, pattern);
+ fs.writeFileSync(configFilePath, yaml.dump(openappsecConfig));
+ })
+ .then(() => {
+ // Return the notifyPolicyUpdate promise chain
+ // notify openappsec to apply the policy
+ return internalNginxOpenappsec.notifyPolicyUpdate().catch((errorMessage) => {
+ console.error('---Error:', errorMessage);
+ const errorMessageForUI = `Error: Policy couldn’t be applied, open-appsec-agent container is not responding.
+ Check if open-appec-agent container is running, then apply open-appsec Configuration
+ again by clicking here:
+
Settings -> open-appsec Advanced -> Save Settings`;
+
+ return Promise.reject(new Error(errorMessageForUI));
+ });
+ })
+ .catch((err) => {
+ logger.error('Error deleting openappsec config:', err);
+ // throw err; // Propagate the error to the caller
+ });
+ },
+
+ /**
+ * Update a node in the openappsec config.
+ * - if the node does not exist, create it.
+ * - if the node exists, update it.
+ * - if openappsecMode is 'inactive', delete the node.
+ *
+ * @param {String} parentNodePath - path to the parent node. e.g. 'policies'.
+ * @param {String} nodeName - name of the node. e.g. 'specific-rules', 'practices', 'log-triggers'.
+ * @param {Object} nodeItemProperties
+ * @param {String} openappsecMode
+ * @param {String} nodeType - 'host' or 'location'
+ * @param {String} hostAppsecMode - to check if the host of a location is inactive.
+ */
+ updateNode: function (parentNodePath, nodeName, nodeItemProperties, openappsecMode, nodeType = 'host', hostAppsecMode = '') {
+ // if no parent node path is specified, use the root of the config object.
+ const parent = parentNodePath ? _.get(this.config, parentNodePath, this.config) : this.config;
+
+ if (!parent) {
+ console.log('parent is not defined');
+ return;
+ }
+
+ let nodeItems = _.find(parent[nodeName], { name: nodeItemProperties.name });
+ if (openappsecMode == 'inactive' && nodeItems) {
+ _.remove(parent[nodeName], { name: nodeItemProperties.name });
+ }
+
+ if (openappsecMode !== 'inactive' || nodeType === 'location' && hostAppsecMode !== 'inactive') {
+ if (!nodeItems) {
+ // create the node from the template if it does not exist.
+ let templateSearchPath = parentNodePath ? `${parentNodePath}.${nodeName}[0]` : `${nodeName}[0]`;
+ nodeItems = _.cloneDeep(_.get(this.configTemplate, templateSearchPath));
+
+ // update the node with the nodeItemProperties. if the nodeType is 'location' and the openappsecMode is 'inactive', only update the name, host, and the (inactive) mode.
+ if (nodeType === 'location' && openappsecMode === 'inactive') {
+ nodeItemProperties = _.pick(nodeItemProperties, ['name', 'host', 'triggers', 'practices', 'mode', 'web-attacks.override-mode']);
+ }
+
+ Object.keys(nodeItemProperties).forEach(key => {
+ _.set(nodeItems, key, nodeItemProperties[key]);
+ });
+ parent[nodeName] = parent[nodeName] || [];
+ parent[nodeName].push(nodeItems);
+ } else {
+ // update the node if it exists.
+ Object.keys(nodeItemProperties).forEach(key => {
+ _.set(nodeItems, key, nodeItemProperties[key]);
+ });
+ }
+ }
+ },
+
+ notifyPolicyUpdate: async function() {
+ if (!constants.USE_NOTIFY_POLICY) {
+ console.log('USE_NOTIFY_POLICY is false');
+ return;
+ }
+ let ports = constants.PORTS;
+ let lastError = null;
+ for (let port of ports) {
+ try {
+ const data = `{"policy_path":"${constants.POLICY_PATH}"}`;
+ const command = `curl -s -o /dev/null -w "%{http_code}" --data '${data}' ${constants.HOSTURL}:${port}/set-apply-policy`;
+ let { stdout } = await execPromise(command);
+ if (stdout === '200') {
+ console.log(`Policy applied successfully on port ${port}`);
+ return;
+ } else {
+ console.log(`Policy Unexpected response code: ${stdout}`);
+ lastError = new Error(`Unexpected response code: ${stdout}`);
+ }
+ } catch (error) {
+ console.log(`Error notifying openappsec to apply the policy on port ${port}: ${error.message}`);
+ lastError = error;
+ }
+ }
+
+ // if (lastError) {
+ // throw lastError;
+ // }
+ },
+
+ /**
+ * Recursively removes nodes from a JavaScript object based on a pattern.
+ *
+ * @param {Object|Array} obj - The object or array to remove nodes from.
+ * @param {RegExp} pattern - The pattern to match against node names.
+ */
+ removeMatchingNodes: function (obj, pattern) {
+ _.forEach(obj, (value, key) => {
+ if (_.isPlainObject(value)) {
+ if (pattern.test(key)) {
+ delete obj[key];
+ } else {
+ this.removeMatchingNodes(value, pattern);
+ }
+ } else if (_.isArray(value)) {
+ _.remove(value, function (item) {
+ return _.isPlainObject(item) && pattern.test(item.name);
+ });
+ value.forEach(item => {
+ if (_.isPlainObject(item)) {
+ this.removeMatchingNodes(item, pattern);
+ }
+ });
+ }
+ });
+ },
+
+ /**
+ * Get the openappsec mode, use_openappsec and minimum_confidence for a proxy host.
+ *
+ * @param {Object} openappsecConfig - openappsec config object
+ * @param {Number} rowId - proxy host id
+ * @returns {Object} { mode, use_openappsec, minimum_confidence }
+ */
+ getOpenappsecFields: (openappsecConfig, rowId) => {
+ const specificRuleName = 'npm-managed-specific-rule-proxyhost-' + rowId;
+
+ const specificRule = _.find(openappsecConfig?.policies['specific-rules'], { name: specificRuleName });
+ const mode = specificRule?.mode || 'inactive';
+ const use_openappsec = mode !== 'inactive' && mode !== undefined;
+
+ const practiceName = 'npm-managed-practice-proxyhost-' + rowId;
+ const practice = _.find(openappsecConfig?.practices, { name: practiceName });
+ const minimum_confidence = practice?.['web-attacks']['minimum-confidence'] || 'high';
+
+ return { mode, use_openappsec, minimum_confidence };
+ },
+
+ /**
+ * get the openappsec config file path.
+ */
+ getConfigFilePath: () => {
+ const configFilePath = path.join(constants.APPSEC_EXT_DIR, constants.APPSEC_CONFIG_FILE_NAME);
+ return configFilePath;
+ },
+
+ /**
+ * A simple wrapper around unlinkSync that writes to the logger
+ *
+ * @param {String} filename
+ */
+ deleteFile: (filename) => {
+ logger.debug('Deleting file: ' + filename);
+ try {
+ fs.unlinkSync(filename);
+ } catch (err) {
+ logger.debug('Could not delete file:', JSON.stringify(err, null, 2));
+ }
+ }
+
+};
+
+module.exports = internalNginxOpenappsec;
\ No newline at end of file
diff --git a/backend/internal/openappsec-log.js b/backend/internal/openappsec-log.js
new file mode 100755
index 00000000..dfa770a5
--- /dev/null
+++ b/backend/internal/openappsec-log.js
@@ -0,0 +1,152 @@
+const fs = require('fs');
+const path = require('path');
+const util = require('util');
+const error = require('../lib/error');
+const { APPSEC_LOG_DIR } = require('../lib/constants');
+
+const internalOpenappsecLog = {
+
+ countTotalLines: async function (directoryPath) {
+ const files = await fs.promises.readdir(directoryPath);
+ const logFiles = files.filter(file => path.extname(file).startsWith('.log'));
+
+ let totalLineCount = 0;
+
+ for (const file of logFiles) {
+ const filePath = path.join(directoryPath, file);
+
+ // Read only the first line of the file
+ const readStream = fs.createReadStream(filePath);
+ const rl = readline.createInterface({ input: readStream });
+ const firstLine = await new Promise(resolve => {
+ rl.on('line', line => {
+ rl.close();
+ resolve(line);
+ });
+ });
+
+ // Check if the first line is a non-data line
+ try {
+ JSON.parse(firstLine);
+ } catch (err) {
+ continue; // Skip this file if the first line is a non-data line
+ }
+
+ // If the first line is a data line, read the rest of the file
+ const content = await fs.promises.readFile(filePath, 'utf8');
+ const lines = content.split('\n');
+ totalLineCount += lines.length;
+ }
+
+ return totalLineCount;
+ },
+
+ processFile: async function (filePath) {
+ const content = await fs.promises.readFile(filePath, 'utf8');
+ const lines = content.split('\n');
+ const dataLines = [];
+
+ for (const line of lines) {
+ try {
+ const json = JSON.parse(line);
+ const groupName = path.basename(filePath, path.extname(filePath));
+ const wrappedObject = {
+ source: groupName,
+ meta: json,
+ serviceName: json.eventSource.serviceName,
+ eventPriority: json.eventPriority,
+ eventSeverity: json.eventSeverity,
+ eventLevel: json.eventLevel,
+ eventTime: json.eventTime,
+ assetName: json.eventSource.assetName,
+ securityAction: json.eventData.securityAction,
+ waapIncidentType: json.eventData.waapIncidentType,
+ httpSourceId: json.eventData.httpSourceId,
+ sourceIP: json.eventData.sourceIP,
+ proxyIP: json.eventData.proxyIP,
+ httpHostName: json.eventData.httpHostName,
+ httpMethod: json.eventData.httpMethod,
+ httpUriPath: json.eventData.httpUriPath,
+ eventTopic: json.eventSource.eventTopic,
+ matchedLocation: json.eventData.matchedLocation,
+ matchedParameter: json.eventData.matchedParameter,
+ matchedSample: json.eventData.matchedSample,
+ eventName: json.eventName
+ };
+ dataLines.push(wrappedObject);
+ } catch (err) {
+ // Ignore lines that don't contain JSON data
+ }
+ }
+
+ return dataLines;
+ },
+
+
+ getAll: function (access, expand, search_query) {
+ return access.can('auditlog:list')
+ .then(async () => {
+ const directoryPath = APPSEC_LOG_DIR;
+ const files = await fs.promises.readdir(directoryPath);
+ const logFiles = files.filter(file => path.extname(file).startsWith('.log'));
+
+ // Sort the logFiles array
+ logFiles.sort((a, b) => {
+ const baseA = path.basename(a, path.extname(a));
+ const baseB = path.basename(b, path.extname(b));
+ return baseA.localeCompare(baseB, undefined, { numeric: true, sensitivity: 'base' });
+ });
+
+ const wrappedObjects = [];
+ for (const file of logFiles) {
+ const filePath = path.join(directoryPath, file);
+ const dataLines = await this.processFile(filePath);
+ wrappedObjects.push(...dataLines);
+ }
+
+ return wrappedObjects;
+ });
+ },
+
+ getPage: function (access, expand, search_query, page, perPage) {
+ return access.can('auditlog:list')
+ .then(async () => {
+ const directoryPath = APPSEC_LOG_DIR;
+ let totalDataLines = await this.countTotalLines(directoryPath);
+
+ const files = await fs.promises.readdir(directoryPath);
+ const logFiles = files.filter(file => path.extname(file).startsWith('.log'));
+
+ // Sort the logFiles array
+ logFiles.sort((a, b) => {
+ const baseA = path.basename(a, path.extname(a));
+ const baseB = path.basename(b, path.extname(b));
+ return baseA.localeCompare(baseB, undefined, { numeric: true, sensitivity: 'base' });
+ });
+
+ const wrappedObjects = [];
+ let lineCount = 0;
+ let start = (page - 1) * perPage;
+ let end = page * perPage;
+
+ for (const file of logFiles) {
+ if (lineCount >= end) {
+ break;
+ }
+
+ const filePath = path.join(directoryPath, file);
+ const dataLines = await this.processFile(filePath);
+ const pageDataLines = dataLines.slice(start - lineCount, end - lineCount);
+ wrappedObjects.push(...pageDataLines);
+ lineCount += pageDataLines.length;
+ }
+
+ return {
+ data: wrappedObjects,
+ totalDataLines: totalDataLines,
+ };
+ });
+ },
+};
+
+module.exports = internalOpenappsecLog;
diff --git a/backend/internal/proxy-host.js b/backend/internal/proxy-host.js
index 02a98da2..25e4fe8b 100644
--- a/backend/internal/proxy-host.js
+++ b/backend/internal/proxy-host.js
@@ -4,8 +4,12 @@ const utils = require('../lib/utils');
const proxyHostModel = require('../models/proxy_host');
const internalHost = require('./host');
const internalNginx = require('./nginx');
+const internalNginxOpenappsec= require('./nginx-openappsec');
const internalAuditLog = require('./audit-log');
const internalCertificate = require('./certificate');
+const fs = require('fs');
+const path = require('path');
+const yaml = require('js-yaml');
function omissions () {
return ['is_deleted'];
@@ -48,9 +52,15 @@ const internalProxyHost = {
data.owner_user_id = access.token.getUserId(1);
data = internalHost.cleanSslHstsData(data);
+ let db_data = _.assign({}, data);
+ // Remove the openappsec fields from data. they are not in the database.
+ delete db_data.use_openappsec;
+ delete db_data.openappsec_mode;
+ delete db_data.minimum_confidence;
+
return proxyHostModel
.query()
- .insertAndFetch(data)
+ .insertAndFetch(db_data)
.then(utils.omitRow(omissions()));
})
.then((row) => {
@@ -84,6 +94,16 @@ const internalProxyHost = {
return row;
});
})
+ .then(row => {
+ return internalNginxOpenappsec.generateConfig(access, row, data)
+ .then(() => {
+ return row;
+ })
+ .catch((err) => {
+ console.log("Error generating openappsec config: " + err);
+ // throw new error.ConfigurationError(err.message);
+ });
+ })
.then((row) => {
// Audit log
data.meta = _.assign({}, data.meta || {}, row.meta);
@@ -159,6 +179,16 @@ const internalProxyHost = {
return row;
}
})
+ .then(row => {
+ return internalNginxOpenappsec.generateConfig(access, row, data)
+ .then(() => {
+ return row;
+ })
+ .catch((err) => {
+ console.log("Error generating openappsec config: " + err);
+ // throw new error.ConfigurationError(err.message);
+ });
+ })
.then((row) => {
// Add domain_names to the data in case it isn't there, so that the audit log renders correctly. The order is important here.
data = _.assign({}, {
@@ -167,6 +197,11 @@ const internalProxyHost = {
data = internalHost.cleanSslHstsData(data, row);
+ // Remove the openappsec fields from data. they are not in the database
+ delete data.use_openappsec;
+ delete data.openappsec_mode;
+ delete data.minimum_confidence;
+
return proxyHostModel
.query()
.where({id: data.id})
@@ -247,6 +282,22 @@ const internalProxyHost = {
if (typeof data.omit !== 'undefined' && data.omit !== null) {
row = _.omit(row, data.omit);
}
+ return row;
+ })
+ .then((row) => {
+ // add openappsec fields to row
+ try {
+ const configFilePath = internalNginxOpenappsec.getConfigFilePath(access);
+ const openappsecConfig = yaml.load(fs.readFileSync(configFilePath, 'utf8'));
+ let result = internalNginxOpenappsec.getOpenappsecFields(openappsecConfig, row.id);
+ row.use_openappsec = result.use_openappsec;
+ row.openappsec_mode = result.mode;
+ row.minimum_confidence = result.minimum_confidence;
+ }
+ catch (e) {
+ console.log("Error reading openappsec config file: " + e);
+ }
+
return row;
});
},
@@ -274,6 +325,14 @@ const internalProxyHost = {
.patch({
is_deleted: 1
})
+ .then(() => {
+ // Delete openappsec config
+ return internalNginxOpenappsec.deleteConfig(access, row)
+ .catch((err) => {
+ throw new error.ConfigurationError(err.message);
+ });
+
+ })
.then(() => {
// Delete Nginx Config
return internalNginx.deleteConfig('proxy_host', row)
@@ -430,6 +489,21 @@ const internalProxyHost = {
return query.then(utils.omitRows(omissions()));
})
.then((rows) => {
+ // add openappsec fields to rows
+ try {
+ const configFilePath = internalNginxOpenappsec.getConfigFilePath(access);
+ const openappsecConfig = yaml.load(fs.readFileSync(configFilePath, 'utf8'));
+ rows.map(function (row, idx) {
+ let result = internalNginxOpenappsec.getOpenappsecFields(openappsecConfig, row.id);
+ rows[idx].use_openappsec = result.use_openappsec;
+ rows[idx].openappsec_mode = result.mode;
+ rows[idx].minimum_confidence = result.minimum_confidence;
+ });
+ }
+ catch (e) {
+ console.log("Error reading openappsec config file: " + e);
+ }
+
if (typeof expand !== 'undefined' && expand !== null && expand.indexOf('certificate') !== -1) {
return internalHost.cleanAllRowsCertificateMeta(rows);
}
diff --git a/backend/internal/setting-openappsec.js b/backend/internal/setting-openappsec.js
new file mode 100755
index 00000000..e009bc9f
--- /dev/null
+++ b/backend/internal/setting-openappsec.js
@@ -0,0 +1,52 @@
+const fs = require('fs');
+const error = require('../lib/error');
+const path = require('path');
+
+const constants = require('../lib/constants');
+
+const internalOpenappsecSetting = {
+ configFilePath: path.join(constants.APPSEC_EXT_DIR, constants.APPSEC_CONFIG_FILE_NAME),
+
+ /**
+ * @param {Access} access
+ * @return {Promise}
+ */
+ getLocalPolicy: (access) => {
+ return access.can('settings:list')
+ .then(() => {
+ try {
+ const filePath = internalOpenappsecSetting.configFilePath
+ if (!fs.existsSync(filePath)) {
+ return;
+ }
+ const fileContent = fs.readFileSync(filePath, 'utf8');
+ const jsonStr = JSON.stringify(fileContent);
+ return jsonStr;
+
+ } catch (err) {
+ console.error(err);
+ }
+ });
+ },
+
+ /**
+ * @param {Access} access
+ * @param {Object} data
+ * @return {Promise}
+ */
+ updateLocalPolicy: (access, data) => {
+ return access.can('settings:list')
+ .then(() => {
+ const filePath = internalOpenappsecSetting.configFilePath
+ const yamlStr = data.local_policy;
+ fs.writeFileSync(filePath, yamlStr, {encoding: 'utf8'});
+ return true;
+ })
+ .catch((err) => {
+ console.error(err);
+ throw new error.ConfigurationError(err.message);
+ });
+ }
+};
+
+module.exports = internalOpenappsecSetting;
diff --git a/backend/lib/constants.js b/backend/lib/constants.js
new file mode 100755
index 00000000..7b961865
--- /dev/null
+++ b/backend/lib/constants.js
@@ -0,0 +1,9 @@
+module.exports = {
+ APPSEC_CONFIG_FILE_NAME: 'local_policy.yaml',
+ APPSEC_EXT_DIR: '/ext/appsec',
+ APPSEC_LOG_DIR: '/ext/appsec-logs',
+ USE_NOTIFY_POLICY: true,
+ PORTS: [7777, 7778],
+ HOSTURL: 'http://127.0.0.1',
+ POLICY_PATH: '/etc/cp/conf/local_policy.yaml',
+};
\ No newline at end of file
diff --git a/backend/package.json b/backend/package.json
index e8f58255..fde84012 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -1,6 +1,6 @@
{
"name": "nginx-proxy-manager",
- "version": "0.0.0",
+ "version": "1.0.0",
"description": "A beautiful interface for creating Nginx endpoints",
"main": "js/index.js",
"dependencies": {
@@ -13,6 +13,7 @@
"express": "^4.17.3",
"express-fileupload": "^1.1.9",
"gravatar": "^1.8.0",
+ "js-yaml": "^4.1.0",
"json-schema-ref-parser": "^8.0.0",
"jsonwebtoken": "^9.0.0",
"knex": "2.4.2",
diff --git a/backend/routes/api/main.js b/backend/routes/api/main.js
index 33cbbc21..5eeea451 100644
--- a/backend/routes/api/main.js
+++ b/backend/routes/api/main.js
@@ -29,8 +29,10 @@ router.use('/schema', require('./schema'));
router.use('/tokens', require('./tokens'));
router.use('/users', require('./users'));
router.use('/audit-log', require('./audit-log'));
+router.use('/openappsec-log', require('./openappsec-log'));
router.use('/reports', require('./reports'));
router.use('/settings', require('./settings'));
+router.use('/openappsec-settings', require('./openappsec-settings'));
router.use('/nginx/proxy-hosts', require('./nginx/proxy_hosts'));
router.use('/nginx/redirection-hosts', require('./nginx/redirection_hosts'));
router.use('/nginx/dead-hosts', require('./nginx/dead_hosts'));
diff --git a/backend/routes/api/openappsec-log.js b/backend/routes/api/openappsec-log.js
new file mode 100755
index 00000000..aa70d48d
--- /dev/null
+++ b/backend/routes/api/openappsec-log.js
@@ -0,0 +1,35 @@
+const express = require('express');
+const jwtdecode = require('../../lib/express/jwt-decode');
+const internalOpenappsecLog = require('../../internal/openappsec-log');
+
+let router = express.Router({
+ caseSensitive: true,
+ strict: true,
+ mergeParams: true
+});
+
+/**
+ * /api/openappsec-log
+ */
+router
+ .route('/')
+ .options((req, res) => {
+ res.sendStatus(204);
+ })
+ .all(jwtdecode())
+
+ /**
+ * GET /api/openappsec-log
+ *
+ * Retrieve all logs
+ */
+ .get((req, res, next) => {
+ return internalOpenappsecLog.getAll(res.locals.access)
+ .then((policy) => {
+ res.status(200)
+ .send(policy);
+ })
+ .catch(next);
+ });
+
+module.exports = router;
diff --git a/backend/routes/api/openappsec-settings.js b/backend/routes/api/openappsec-settings.js
new file mode 100755
index 00000000..dcda2333
--- /dev/null
+++ b/backend/routes/api/openappsec-settings.js
@@ -0,0 +1,49 @@
+const express = require('express');
+const jwtdecode = require('../../lib/express/jwt-decode');
+const internalOpenappsecSetting = require('../../internal/setting-openappsec');
+
+let router = express.Router({
+ caseSensitive: true,
+ strict: true,
+ mergeParams: true
+});
+
+/**
+ * /api/openappsec-settings
+ */
+router
+ .route('/')
+ .options((req, res) => {
+ res.sendStatus(204);
+ })
+ .all(jwtdecode())
+
+ /**
+ * GET /api/openappsec-settings
+ *
+ * Retrieve the open-appsec local policy.
+ */
+ .get((req, res, next) => {
+ return internalOpenappsecSetting.getLocalPolicy(res.locals.access)
+ .then((policy) => {
+ res.status(200)
+ .send(policy);
+ })
+ .catch(next);
+ })
+
+ /**
+ * PUT /api/openappsec-settings
+ *
+ * Update the open-appsec local policy.
+ */
+ .put((req, res, next) => {
+ return internalOpenappsecSetting.updateLocalPolicy(res.locals.access, req.body)
+ .then((result) => {
+ res.status(200)
+ .send(result);
+ })
+ .catch(next);
+ });
+
+module.exports = router;
diff --git a/backend/schema/definitions.json b/backend/schema/definitions.json
index 4b4f3405..b3c87b57 100644
--- a/backend/schema/definitions.json
+++ b/backend/schema/definitions.json
@@ -137,6 +137,18 @@
}
]
},
+ "openappsec_mode": {
+ "description": "openappsec_mode ID",
+ "type": "string",
+ "minLength": 1,
+ "maxLength": 255
+ },
+ "minimum_confidence": {
+ "description": "minimum_confidence ID",
+ "type": "string",
+ "minLength": 1,
+ "maxLength": 255
+ },
"access_list_id": {
"description": "Access List ID",
"example": 1234,
@@ -231,6 +243,11 @@
"example": true,
"type": "boolean"
},
+ "use_openappsec": {
+ "description": "Use openappsec",
+ "example": true,
+ "type": "boolean"
+ },
"caching_enabled": {
"description": "Should we cache assets",
"example": true,
diff --git a/backend/schema/endpoints/proxy-hosts.json b/backend/schema/endpoints/proxy-hosts.json
index 9a3fff2f..029fd61f 100644
--- a/backend/schema/endpoints/proxy-hosts.json
+++ b/backend/schema/endpoints/proxy-hosts.json
@@ -50,6 +50,15 @@
"block_exploits": {
"$ref": "../definitions.json#/definitions/block_exploits"
},
+ "use_openappsec": {
+ "$ref": "../definitions.json#/definitions/use_openappsec"
+ },
+ "openappsec_mode": {
+ "$ref": "../definitions.json#/definitions/openappsec_mode"
+ },
+ "minimum_confidence": {
+ "$ref": "../definitions.json#/definitions/minimum_confidence"
+ },
"caching_enabled": {
"$ref": "../definitions.json#/definitions/caching_enabled"
},
@@ -104,6 +113,15 @@
},
"advanced_config": {
"type": "string"
+ },
+ "use_openappsec": {
+ "type": "boolean"
+ },
+ "openappsec_mode": {
+ "type": "string"
+ },
+ "minimum_confidence": {
+ "type": "string"
}
}
}
@@ -149,6 +167,15 @@
"block_exploits": {
"$ref": "#/definitions/block_exploits"
},
+ "use_openappsec": {
+ "$ref": "#/definitions/use_openappsec"
+ },
+ "openappsec_mode": {
+ "$ref": "#/definitions/openappsec_mode"
+ },
+ "minimum_confidence": {
+ "$ref": "#/definitions/minimum_confidence"
+ },
"caching_enabled": {
"$ref": "#/definitions/caching_enabled"
},
@@ -239,6 +266,15 @@
"block_exploits": {
"$ref": "#/definitions/block_exploits"
},
+ "use_openappsec": {
+ "$ref": "#/definitions/use_openappsec"
+ },
+ "openappsec_mode": {
+ "$ref": "#/definitions/openappsec_mode"
+ },
+ "minimum_confidence": {
+ "$ref": "#/definitions/minimum_confidence"
+ },
"caching_enabled": {
"$ref": "#/definitions/caching_enabled"
},
@@ -312,6 +348,15 @@
"block_exploits": {
"$ref": "#/definitions/block_exploits"
},
+ "use_openappsec": {
+ "$ref": "#/definitions/use_openappsec"
+ },
+ "openappsec_mode": {
+ "$ref": "#/definitions/openappsec_mode"
+ },
+ "minimum_confidence": {
+ "$ref": "#/definitions/minimum_confidence"
+ },
"caching_enabled": {
"$ref": "#/definitions/caching_enabled"
},
diff --git a/backend/templates/local-policy-open-appsec-enabled-for-proxy-host.yaml b/backend/templates/local-policy-open-appsec-enabled-for-proxy-host.yaml
new file mode 100755
index 00000000..6b560b3f
--- /dev/null
+++ b/backend/templates/local-policy-open-appsec-enabled-for-proxy-host.yaml
@@ -0,0 +1,122 @@
+# This example is for NPM Proxy Host with open-appsec enabled,
+# Enforcement Mode set to Prevent/Learn, hostname web.server.com/example
+
+policies:
+ default:
+ triggers:
+ - appsec-default-log-trigger
+ mode: inactive
+ practices:
+ - webapp-default-practice
+ custom-response: appsec-default-web-user-response
+ specific-rules:
+ - host: web.server.com/example
+ # as set in "Edit Proxy Host" in "Domain Names" field
+ # IMPORTANT LIMITATION: Currently open-appsec declarative with CRD version 1.0 only supports single host entry per specific rule
+ # This will be resolved with new CRDs 2.0
+ name: npm-managed-specific-rule-proxyhost-1
+ # This “name” key will be the actual reference to a specific Reverse Proxy object defined in NPM
+ triggers:
+ - npm-managed-log-trigger-proxyhost-1
+ mode: prevent-learn
+ practices:
+ - npm-managed-practice-proxyhost-1
+
+practices:
+ - name: webapp-default-practice
+ web-attacks:
+ max-body-size-kb: 1000000
+ max-header-size-bytes: 102400
+ max-object-depth: 40
+ max-url-size-bytes: 32768
+ minimum-confidence: high
+ override-mode: inactive
+ protections:
+ csrf-protection: inactive
+ error-disclosure: inactive
+ non-valid-http-methods: false
+ open-redirect: inactive
+ anti-bot:
+ injected-URIs: []
+ validated-URIs: []
+ override-mode: inactive
+ snort-signatures:
+ configmap: []
+ override-mode: inactive
+ openapi-schema-validation:
+ configmap: []
+ override-mode: inactive
+
+ - name: npm-managed-practice-proxyhost-1
+ web-attacks:
+ max-body-size-kb: 1000000
+ max-header-size-bytes: 102400
+ max-object-depth: 40
+ max-url-size-bytes: 32768
+ minimum-confidence: high
+ override-mode: inactive
+ protections:
+ csrf-protection: inactive
+ error-disclosure: inactive
+ non-valid-http-methods: false
+ open-redirect: inactive
+ anti-bot:
+ injected-URIs: []
+ validated-URIs: []
+ override-mode: inactive
+ snort-signatures:
+ configmap: []
+ override-mode: inactive
+ openapi-schema-validation:
+ configmap: []
+ override-mode: inactive
+
+log-triggers:
+ - name: appsec-default-log-trigger
+ access-control-logging:
+ allow-events: false
+ drop-events: true
+ additional-suspicious-events-logging:
+ enabled: true
+ minimum-severity: high
+ response-body: false
+ response-code: true
+ appsec-logging:
+ all-web-requests: false
+ detect-events: true
+ prevent-events: true
+ extended-logging:
+ http-headers: false
+ request-body: false
+ url-path: true
+ url-query: true
+ log-destination:
+ cloud: false
+ stdout:
+ format: json
+ - name: npm-managed-log-trigger-proxyhost-1
+ access-control-logging:
+ allow-events: false
+ drop-events: true
+ additional-suspicious-events-logging:
+ enabled: true
+ minimum-severity: high
+ response-body: false
+ appsec-logging:
+ all-web-requests: false
+ detect-events: true
+ prevent-events: true
+ extended-logging:
+ http-headers: false
+ request-body: false
+ url-path: false
+ url-query: false
+ log-destination:
+ cloud: false
+ stdout:
+ format: json
+
+custom-responses:
+ - name: appsec-default-web-user-response
+ mode: response-code-only
+ http-response-code: 403
\ No newline at end of file
diff --git a/backend/templates/openappsec.conf b/backend/templates/openappsec.conf
new file mode 100755
index 00000000..bc350cab
--- /dev/null
+++ b/backend/templates/openappsec.conf
@@ -0,0 +1,16 @@
+policies:
+ default:
+ triggers:
+ - appsec-default-log-trigger
+ mode: inactive
+ practices:
+ - webapp-default-practice
+ custom-response: appsec-default-web-user-response
+ specific-rules:
+ - host: {{ domain_names.first }}
+ triggers:
+ - appsec-default-log-trigger
+ mode: {{openappsec_mode}}
+ practices:
+ - webapp-default-practice
+ custom-response: appsec-default-web-user-response
\ No newline at end of file
diff --git a/deployment/docker-compose.yaml b/deployment/docker-compose.yaml
index b610742f..99df149a 100644
--- a/deployment/docker-compose.yaml
+++ b/deployment/docker-compose.yaml
@@ -1,10 +1,10 @@
-version: '3.8'
+version: '3.3'
# docker compose for npm open-appsec integration
services:
appsec-npm:
- container_name: appsec-npm
- image: 'ghcr.io/openappsec/appsec-npm:latest'
+ container_name: npm-attachment
+ image: 'ghcr.io/openappsec/nginx-proxy-manager-attachment:latest'
ipc: host
restart: unless-stopped
ports:
diff --git a/deployment/local_policy.yaml b/deployment/local_policy.yaml
index 8aaf15a8..e288a7a1 100644
--- a/deployment/local_policy.yaml
+++ b/deployment/local_policy.yaml
@@ -42,6 +42,7 @@ log-triggers:
enabled: true
minimum-severity: high
response-body: false
+ response-code: true
appsec-logging:
all-web-requests: false
detect-events: true
@@ -49,8 +50,8 @@ log-triggers:
extended-logging:
http-headers: false
request-body: false
- url-path: false
- url-query: false
+ url-path: true
+ url-query: true
log-destination:
cloud: false
stdout:
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 82ec9355..df4d1f61 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -42,9 +42,20 @@ WORKDIR /app
RUN yarn install \
&& yarn cache clean
+# add open-appsec attachment
+RUN mkdir -p /usr/lib/nginx
+RUN mkdir -p /usr/lib/nginx/modules
+COPY docker/lib/libngx_module.so /usr/lib/nginx/modules/libngx_module.so
+COPY docker/lib/libosrc_nginx_attachment_util.so /usr/lib/libosrc_nginx_attachment_util.so
+COPY docker/lib/libosrc_compression_utils.so /usr/lib/libosrc_compression_utils.so
+COPY docker/lib/libosrc_shmem_ipc.so /usr/lib/libosrc_shmem_ipc.so
+
# add late to limit cache-busting by modifications
COPY docker/rootfs /
+# patch nginx.conf for open-appsec attachment
+RUN sed -i -e '/include \/etc\/nginx\/modules\/\*\.conf/a\load_module /usr/lib/nginx/modules/libngx_module.so;' -e '/http {/a\\tcp_worker_processes auto;' /etc/nginx/nginx.conf
+
# Remove frontend service not required for prod, dev nginx config as well
RUN rm -rf /etc/s6-overlay/s6-rc.d/user/contents.d/frontend /etc/nginx/conf.d/dev.conf \
&& chmod 644 /etc/logrotate.d/nginx-proxy-manager \
diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml
index 6d8cf87c..ce659441 100644
--- a/docker/docker-compose.dev.yml
+++ b/docker/docker-compose.dev.yml
@@ -33,6 +33,8 @@ services:
volumes:
- npm_data:/data
- le_data:/etc/letsencrypt
+ - ../open-appsec-agent-deployment/localconfig:/ext/appsec
+ - ../open-appsec-agent-deployment/logs:/ext/appsec-logs
- ../backend:/app
- ../frontend:/app/frontend
- ../global:/app/global
diff --git a/docker/lib/libngx_module.so b/docker/lib/libngx_module.so
new file mode 100644
index 00000000..f764515e
Binary files /dev/null and b/docker/lib/libngx_module.so differ
diff --git a/docker/lib/libosrc_compression_utils.so b/docker/lib/libosrc_compression_utils.so
new file mode 100644
index 00000000..0c2a832a
Binary files /dev/null and b/docker/lib/libosrc_compression_utils.so differ
diff --git a/docker/lib/libosrc_nginx_attachment_util.so b/docker/lib/libosrc_nginx_attachment_util.so
new file mode 100644
index 00000000..52c2ee36
Binary files /dev/null and b/docker/lib/libosrc_nginx_attachment_util.so differ
diff --git a/docker/lib/libosrc_shmem_ipc.so b/docker/lib/libosrc_shmem_ipc.so
new file mode 100644
index 00000000..5aa5ec11
Binary files /dev/null and b/docker/lib/libosrc_shmem_ipc.so differ
diff --git a/docs/yarn.lock b/docs/yarn.lock
index 3a38e241..85dafbb0 100644
--- a/docs/yarn.lock
+++ b/docs/yarn.lock
@@ -1808,7 +1808,16 @@ array-unique@^0.3.2:
resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428"
integrity sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg=
-asn1.js@^5.2.0, asn1.js@^5.4.1:
+asn1.js@^4.0.0:
+ version "4.10.1"
+ resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-4.10.1.tgz#b9c2bf5805f1e64aadeed6df3a2bfafb5a73f5a0"
+ integrity sha512-p32cOF5q0Zqs9uBiONKYLm6BClCoBCM5O9JfeUSlnQLBTxYdTK+pW+nXflm8UkKd2UYlEbYz5qEi0JuZR9ckSw==
+ dependencies:
+ bn.js "^4.0.0"
+ inherits "^2.0.1"
+ minimalistic-assert "^1.0.0"
+
+asn1.js@^5.4.1:
version "5.4.1"
resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-5.4.1.tgz#11a980b84ebb91781ce35b0fdc2ee294e3783f07"
integrity sha512-+I//4cYPccV8LdmBLiX8CYvf9Sp3vQsrqu2QNXRcrbiWvcx/UdlFiqUJJzxRQxgsZmvhXhn4cSKeSmoFjVdupA==
@@ -2056,10 +2065,10 @@ bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.11.9:
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88"
integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==
-bn.js@^5.0.0, bn.js@^5.1.2, bn.js@^5.2.1:
- version "5.2.1"
- resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70"
- integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==
+bn.js@^5.1.1, bn.js@^5.1.2:
+ version "5.1.2"
+ resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.2.tgz#c9686902d3c9a27729f43ab10f9d79c2004da7b0"
+ integrity sha512-40rZaf3bUNKTVYu9sIeeEGOg7g14Yvnj9kH7b50EiwX0Q7A6umbvfI5tvHaOERH0XigqKkfLkFQxzb4e6CIXnA==
body-parser@1.19.2, body-parser@^1.19.0:
version "1.19.2"
@@ -2175,28 +2184,28 @@ browserify-des@^1.0.0, browserify-des@^1.0.2:
inherits "^2.0.1"
safe-buffer "^5.1.2"
-browserify-rsa@^4.0.0, browserify-rsa@^4.0.1, browserify-rsa@^4.1.0:
- version "4.1.0"
- resolved "https://registry.yarnpkg.com/browserify-rsa/-/browserify-rsa-4.1.0.tgz#b2fd06b5b75ae297f7ce2dc651f918f5be158c8d"
- integrity sha512-AdEER0Hkspgno2aR97SAf6vi0y0k8NuOpGnVH3O99rcA5Q6sh8QxcngtHuJ6uXwnfAXNM4Gn1Gb7/MV1+Ymbog==
+browserify-rsa@^4.0.0, browserify-rsa@^4.0.1:
+ version "4.0.1"
+ resolved "https://registry.yarnpkg.com/browserify-rsa/-/browserify-rsa-4.0.1.tgz#21e0abfaf6f2029cf2fafb133567a701d4135524"
+ integrity sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ=
dependencies:
- bn.js "^5.0.0"
+ bn.js "^4.1.0"
randombytes "^2.0.1"
browserify-sign@^4.0.0, browserify-sign@^4.2.1:
- version "4.2.2"
- resolved "https://registry.yarnpkg.com/browserify-sign/-/browserify-sign-4.2.2.tgz#e78d4b69816d6e3dd1c747e64e9947f9ad79bc7e"
- integrity sha512-1rudGyeYY42Dk6texmv7c4VcQ0EsvVbLwZkA+AQB7SxvXxmcD93jcHie8bzecJ+ChDlmAm2Qyu0+Ccg5uhZXCg==
+ version "4.2.1"
+ resolved "https://registry.yarnpkg.com/browserify-sign/-/browserify-sign-4.2.1.tgz#eaf4add46dd54be3bb3b36c0cf15abbeba7956c3"
+ integrity sha512-/vrA5fguVAKKAVTNJjgSm1tRQDHUU6DbwO9IROu/0WAzC8PKhucDSh18J0RMvVeHAn5puMd+QHC2erPRNf8lmg==
dependencies:
- bn.js "^5.2.1"
- browserify-rsa "^4.1.0"
+ bn.js "^5.1.1"
+ browserify-rsa "^4.0.1"
create-hash "^1.2.0"
create-hmac "^1.1.7"
- elliptic "^6.5.4"
+ elliptic "^6.5.3"
inherits "^2.0.4"
- parse-asn1 "^5.1.6"
- readable-stream "^3.6.2"
- safe-buffer "^5.2.1"
+ parse-asn1 "^5.1.5"
+ readable-stream "^3.6.0"
+ safe-buffer "^5.2.0"
browserify-zlib@^0.2.0:
version "0.2.0"
@@ -3739,7 +3748,7 @@ electron-to-chromium@^1.3.522, electron-to-chromium@^1.3.719:
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.739.tgz#f07756aa92cabd5a6eec6f491525a64fe62f98b9"
integrity sha512-+LPJVRsN7hGZ9EIUUiWCpO7l4E3qBYHNadazlucBfsXBbccDFNKUBAgzE68FnkWGJPwD/AfKhSzL+G+Iqb8A4A==
-elliptic@^6.5.3, elliptic@^6.5.4:
+elliptic@^6.5.3:
version "6.5.4"
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb"
integrity sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==
@@ -7186,13 +7195,14 @@ parent-module@^1.0.0:
dependencies:
callsites "^3.0.0"
-parse-asn1@^5.0.0, parse-asn1@^5.1.5, parse-asn1@^5.1.6:
- version "5.1.6"
- resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.6.tgz#385080a3ec13cb62a62d39409cb3e88844cdaed4"
- integrity sha512-RnZRo1EPU6JBnra2vGHj0yhp6ebyjBZpmUCLHWiFhxlzvBCCpAuZ7elsBp1PVAbQN0/04VD/19rfzlBSwLstMw==
+parse-asn1@^5.0.0, parse-asn1@^5.1.5:
+ version "5.1.5"
+ resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.5.tgz#003271343da58dc94cace494faef3d2147ecea0e"
+ integrity sha512-jkMYn1dcJqF6d5CpU689bq7w/b5ALS9ROVSpQDPrZsqqesUJii9qutvoT5ltGedNXMO2e16YUWIghG9KxaViTQ==
dependencies:
- asn1.js "^5.2.0"
+ asn1.js "^4.0.0"
browserify-aes "^1.0.0"
+ create-hash "^1.1.0"
evp_bytestokey "^1.0.0"
pbkdf2 "^3.0.3"
safe-buffer "^5.1.1"
@@ -8056,10 +8066,10 @@ rc@^1.2.8:
string_decoder "~1.1.1"
util-deprecate "~1.0.1"
-"readable-stream@2 || 3", readable-stream@3, readable-stream@^3.0.2, readable-stream@^3.0.6, readable-stream@^3.1.1, readable-stream@^3.5.0, readable-stream@^3.6.0, readable-stream@^3.6.2:
- version "3.6.2"
- resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.2.tgz#56a9b36ea965c00c5a93ef31eb111a0f11056967"
- integrity sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==
+"readable-stream@2 || 3", readable-stream@3, readable-stream@^3.0.2, readable-stream@^3.0.6, readable-stream@^3.1.1, readable-stream@^3.5.0, readable-stream@^3.6.0:
+ version "3.6.0"
+ resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198"
+ integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==
dependencies:
inherits "^2.0.3"
string_decoder "^1.1.1"
diff --git a/frontend/app-images/open-appsec-logo.svg b/frontend/app-images/open-appsec-logo.svg
new file mode 100755
index 00000000..57b41551
--- /dev/null
+++ b/frontend/app-images/open-appsec-logo.svg
@@ -0,0 +1,68 @@
+
+
diff --git a/frontend/html/login.ejs b/frontend/html/login.ejs
index bc4b9a27..d24a76e3 100644
--- a/frontend/html/login.ejs
+++ b/frontend/html/login.ejs
@@ -1,9 +1,9 @@
<% var title = 'Login – Nginx Proxy Manager' %>
<%- include partials/header.ejs %>
-