-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #272 from PerimeterX/release/v3.9.0
Release/v3.9.0 to master
- Loading branch information
Showing
12 changed files
with
386 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const { ORIGIN_HEADER, ACCESS_CONTROL_REQUEST_METHOD_HEADER } = require('./utils/constants'); | ||
|
||
function isPreflightRequest(request) { | ||
return request.method.toUpperCase() === 'OPTIONS' && request.get(ORIGIN_HEADER) && request.get(ACCESS_CONTROL_REQUEST_METHOD_HEADER); | ||
} | ||
|
||
function runPreflightCustomHandler(pxConfig, request) { | ||
const corsCustomPreflightFunction = pxConfig.CORS_CUSTOM_PREFLIGHT_HANDLER; | ||
|
||
if (corsCustomPreflightFunction) { | ||
try { | ||
return corsCustomPreflightFunction(request); | ||
} catch (e) { | ||
pxConfig.logger.debug(`Error while executing custom preflight handler: ${e}`); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function isCorsRequest(request) { | ||
return request.get(ORIGIN_HEADER); | ||
} | ||
|
||
function getCorsBlockHeaders(request, pxConfig, pxCtx) { | ||
let corsHeaders = getDefaultCorsHeaders(request); | ||
const createCustomCorsHeaders = pxConfig.CORS_CREATE_CUSTOM_BLOCK_RESPONSE_HEADERS; | ||
|
||
if (createCustomCorsHeaders) { | ||
try { | ||
corsHeaders = createCustomCorsHeaders(pxCtx, request); | ||
} catch (e) { | ||
pxConfig.logger.debug(`Caught error in px_cors_create_custom_block_response_headers custom function: ${e}`); | ||
} | ||
} | ||
|
||
return corsHeaders; | ||
} | ||
|
||
function getDefaultCorsHeaders(request) { | ||
const originHeader = request.get(ORIGIN_HEADER); | ||
|
||
if (!originHeader) { | ||
return {}; | ||
} | ||
|
||
return { 'Access-Control-Allow-Origin': originHeader, 'Access-Control-Allow-Credentials': 'true' }; | ||
} | ||
|
||
module.exports = { | ||
isPreflightRequest, | ||
runPreflightCustomHandler, | ||
isCorsRequest, | ||
getCorsBlockHeaders, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.