|
5 | 5 |
|
6 | 6 | # [PerimeterX](http://www.perimeterx.com) Express.js Middleware
|
7 | 7 |
|
8 |
| -> Latest stable version: [v7.5.0](https://www.npmjs.com/package/perimeterx-node-express) |
| 8 | +> Latest stable version: [v7.6.0](https://www.npmjs.com/package/perimeterx-node-express) |
9 | 9 |
|
10 | 10 | ## Table of Contents
|
11 | 11 |
|
|
14 | 14 | - [Configuration](#configuration)
|
15 | 15 | - [Required Configuration](#requiredConfiguration)
|
16 | 16 | - [Optional Configuration](#optionalConfiguration)
|
17 |
| - - [Module Enabled](#moduleEnabled) |
18 |
| - - [Module Mode](#moduleMode) |
19 |
| - - [Blocking Score](#blockingScore) |
20 |
| - - [Send Page Activities](#sendPageActivities) |
21 |
| - - [Send Block Activities](#sendBlockActivities) |
22 |
| - - [Logger Severity](#loggerSeverity) |
23 |
| - - [Sensitive Routes](#sensitiveRoutes) |
24 |
| - - [Enforced Specific Routes](#enforcedSpecificRoutes) |
25 |
| - - [Monitored Specific Routes](#monitoredSpecificRoutes) |
26 |
| - - [Filter By Route](#filterByRoute) |
27 |
| - - [Sensitive Headers](#sensitiveHeaders) |
28 |
| - - [IP Headers](#ipHeaders) |
29 |
| - - [First Party Enabled](#firstPartyEnabled) |
30 |
| - - [CD First Party Enabled](#CDFirstPartyEnabled) |
31 |
| - - [Custom Request Handler](#customRequestHandler) |
32 |
| - - [Additional Activity Handler](#additionalActivityHandler) |
33 |
| - - [Enrich Custom Parameters](#enrichCustomParams) |
34 |
| - - [CSS Ref](#cssRef) |
35 |
| - - [JS Ref](#jsRef) |
36 |
| - - [Custom Logo](#customLogo) |
37 |
| - - [Secured PXHD cookie](#securedpxhd) |
38 |
| - - [Proxy Support](#proxySupport) |
39 |
| - - [Custom Cookie Header](#customCookieHeader) |
40 |
| - - [Filter Traffic by User Agent](#filterByUserAgent) |
41 |
| - - [Filter Traffic by IP](#filterByIP) |
42 |
| - - [Filter Traffic by HTTP Method](#filterByMethod) |
43 |
| - - [Test Block Flow on Monitoring Mode](#bypassMonitorHeader) |
44 |
| - - [CSP Enabled](#cspEnabled) |
45 |
| - - [CSP Policy Refresh Interval](#cspPolicyRefreshIntervalMinutes) |
46 |
| - - [CSP Invalidate Policy Interval](#cspNoUpdatesMaxIntervalMinutes) |
47 |
| - - [Login Credentials Extraction](#loginCredentialsExtraction) |
48 |
| - - [JWT](#JWT) |
| 17 | + - [Module Enabled](#moduleEnabled) |
| 18 | + - [Module Mode](#moduleMode) |
| 19 | + - [Blocking Score](#blockingScore) |
| 20 | + - [Send Page Activities](#sendPageActivities) |
| 21 | + - [Send Block Activities](#sendBlockActivities) |
| 22 | + - [Logger Severity](#loggerSeverity) |
| 23 | + - [Sensitive Routes](#sensitiveRoutes) |
| 24 | + - [Enforced Specific Routes](#enforcedSpecificRoutes) |
| 25 | + - [Monitored Specific Routes](#monitoredSpecificRoutes) |
| 26 | + - [Filter By Route](#filterByRoute) |
| 27 | + - [Sensitive Headers](#sensitiveHeaders) |
| 28 | + - [IP Headers](#ipHeaders) |
| 29 | + - [First Party Enabled](#firstPartyEnabled) |
| 30 | + - [CD First Party Enabled](#CDFirstPartyEnabled) |
| 31 | + - [Custom Request Handler](#customRequestHandler) |
| 32 | + - [Additional Activity Handler](#additionalActivityHandler) |
| 33 | + - [Enrich Custom Parameters](#enrichCustomParams) |
| 34 | + - [CSS Ref](#cssRef) |
| 35 | + - [JS Ref](#jsRef) |
| 36 | + - [Custom Logo](#customLogo) |
| 37 | + - [Secured PXHD cookie](#securedpxhd) |
| 38 | + - [Proxy Support](#proxySupport) |
| 39 | + - [Custom Cookie Header](#customCookieHeader) |
| 40 | + - [Filter Traffic by User Agent](#filterByUserAgent) |
| 41 | + - [Filter Traffic by IP](#filterByIP) |
| 42 | + - [Filter Traffic by HTTP Method](#filterByMethod) |
| 43 | + - [Test Block Flow on Monitoring Mode](#bypassMonitorHeader) |
| 44 | + - [CSP Enabled](#cspEnabled) |
| 45 | + - [CSP Policy Refresh Interval](#cspPolicyRefreshIntervalMinutes) |
| 46 | + - [CSP Invalidate Policy Interval](#cspNoUpdatesMaxIntervalMinutes) |
| 47 | + - [Login Credentials Extraction](#loginCredentialsExtraction) |
| 48 | + - [JWT](#JWT) |
| 49 | + - [CORS support](#px_cors_support) |
49 | 50 | - [Code Defender Middleware - cdMiddleware](#cdMiddleware)
|
50 | 51 | - [Advanced Blocking Response](#advancedBlockingResponse)
|
51 | 52 | - [Multiple App Support](#multipleAppSupport)
|
@@ -853,6 +854,85 @@ const pxConfig = {
|
853 | 854 | }
|
854 | 855 | ```
|
855 | 856 |
|
| 857 | +#### <a name="px_cors_support"></a>CORS Support |
| 858 | + |
| 859 | +Enable CORS support for the enforcer. This will allow the enforcer to filter out preflight requests and to add CORS headers to block responses. |
| 860 | +This will ensure responses are not blocked by the browser. |
| 861 | +CORS support is enabled by default. |
| 862 | + |
| 863 | +`px_cors_support_enabled` - Enable CORS support for the enforcer. |
| 864 | + |
| 865 | +**Default:** `false` |
| 866 | + |
| 867 | +`px_cors_custom_preflight_handler` - Custom preflight handler. This function will be called for preflight requests and returns response that will return to the client. |
| 868 | + |
| 869 | +```js |
| 870 | +// Example |
| 871 | +const pxConfig = { |
| 872 | + ... |
| 873 | + px_cors_custom_preflight_handler: function(request) { |
| 874 | + const response = { |
| 875 | + status: '204', |
| 876 | + }; |
| 877 | + |
| 878 | + response.headers = { |
| 879 | + 'Access-Control-Allow-Origin': request.headers['origin'] || '*', |
| 880 | + 'Access-Control-Allow-Methods': request.method, |
| 881 | + 'Access-Control-Allow-Headers': request.headers['access-control-request-headers'], |
| 882 | + 'Access-Control-Allow-Credentials': 'true', |
| 883 | + 'Access-Control-Max-Age': '86400', |
| 884 | + }; |
| 885 | + |
| 886 | + return response; |
| 887 | + }; |
| 888 | +} |
| 889 | +``` |
| 890 | + |
| 891 | +`px_cors_preflight_request_filter_enabled` - Filter out preflight requests from validation flow. |
| 892 | + |
| 893 | +**Default:** false |
| 894 | + |
| 895 | +Enable CORS support for the enforcer: |
| 896 | +``` JS |
| 897 | +const pxConfig = { |
| 898 | + ... |
| 899 | + px_cors_support_enabled: true, |
| 900 | + px_cors_preflight_request_filter_enabled: true, |
| 901 | + ... |
| 902 | +}; |
| 903 | +``` |
| 904 | + |
| 905 | +The default CORS policy when blocking a request is as follows: |
| 906 | +``` JS |
| 907 | +Access-Control-Allow-Origin: request origin |
| 908 | +Access-Control-Allow-Credentials: true |
| 909 | +``` |
| 910 | + |
| 911 | +The default CORS policy can be overridden by setting the following properties: |
| 912 | + |
| 913 | +`px_cors_create_custom_block_response_headers` |
| 914 | + |
| 915 | +Synchronous function supplied by the customer which gets the original request and returns an array of custom headers to be added to the block response. |
| 916 | +Return type should be an array of objects as follows: |
| 917 | + |
| 918 | +```js |
| 919 | +// Example |
| 920 | +const pxConfig = { |
| 921 | + ... |
| 922 | + px_cors_create_custom_block_response_headers: function(request) { |
| 923 | + return { |
| 924 | + 'Access-Control-Allow-Origin': request.headers['origin'], |
| 925 | + 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS', |
| 926 | + 'Access-Control-Allow-Headers': 'Content-Type, Authorization', |
| 927 | + 'Access-Control-Allow-Credentials': 'true' |
| 928 | + } |
| 929 | + }; |
| 930 | + ... |
| 931 | +}; |
| 932 | +``` |
| 933 | + |
| 934 | +**Default:** `null` |
| 935 | + |
856 | 936 | ## <a name="cdMiddleware"></a> Code Defender Middleware - cdMiddleware
|
857 | 937 |
|
858 | 938 | Code Defender's middleware to handle the enforcement of CSP headers on responses returned to the client.
|
@@ -972,7 +1052,7 @@ server.use('/app2', app1Router);
|
972 | 1052 | server.listen(8081, () => {
|
973 | 1053 | console.log('server started');
|
974 | 1054 | });
|
975 |
| -``` |
| 1055 | +`` |
976 | 1056 |
|
977 | 1057 | ## <a name=“additionalInformation”></a> Additional Information
|
978 | 1058 |
|
|
0 commit comments