diff --git a/ilc/package-lock.json b/ilc/package-lock.json index 19df79b8..872a2baf 100644 --- a/ilc/package-lock.json +++ b/ilc/package-lock.json @@ -10,7 +10,7 @@ "license": "Apache-2.0", "dependencies": { "@namecheap/error-extender": "^2.2.1", - "@namecheap/tailorx": "^8.1.0", + "@namecheap/tailorx": "^8.2.0", "@newrelic/native-metrics": "^11.0.0", "agentkeepalive": "^4.5.0", "axios": "^1.7.7", @@ -2195,9 +2195,10 @@ "integrity": "sha512-GeFZT8ntXN7N91jyHy7qEw4Kq0v66kV/7+/EQJHHsdzbko44wtrDvr+Mj6Td9soqlZGQz8VoOUa9XrHSauVcLA==" }, "node_modules/@namecheap/tailorx": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@namecheap/tailorx/-/tailorx-8.1.0.tgz", - "integrity": "sha512-TSCfaKfUd14QQkZrZHYIP/vj5zONxhCNtpTkpd15BN0XPl2idHwJFBDaNgKqGh/iZiHesCcXMsM6sQRIgizmKg==", + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/@namecheap/tailorx/-/tailorx-8.2.0.tgz", + "integrity": "sha512-RAeOeaiw1btqowbkc5BfklXGBFUw4R4SkVCFNAVxEj9Hc/qaeo1SnDF99MI8nTiixefaZCWvyHhcp8R0/iwO3A==", + "license": "Apache-2.0", "dependencies": { "@namecheap/error-extender": "^2.0.0", "agentkeepalive": "^4.5.0", diff --git a/ilc/package.json b/ilc/package.json index 917d067b..9a1ed481 100644 --- a/ilc/package.json +++ b/ilc/package.json @@ -21,7 +21,7 @@ "license": "Apache-2.0", "dependencies": { "@namecheap/error-extender": "^2.2.1", - "@namecheap/tailorx": "^8.1.0", + "@namecheap/tailorx": "^8.2.0", "@newrelic/native-metrics": "^11.0.0", "agentkeepalive": "^4.5.0", "axios": "^1.7.7", diff --git a/ilc/server/tailor/configs-injector.js b/ilc/server/tailor/configs-injector.js index be6b09fe..36223a90 100644 --- a/ilc/server/tailor/configs-injector.js +++ b/ilc/server/tailor/configs-injector.js @@ -11,6 +11,7 @@ module.exports = class ConfigsInjector { #cdnUrl; #jsInjectionPlaceholder = ''; #cssInjectionPlaceholder = ''; + #markedProdTags = /.*?/gims; constructor(newrelic, cdnUrl = null, nrCustomClientJsWrapper = null, nrAutomaticallyInjectClientScript = true) { this.#newrelic = newrelic; @@ -73,6 +74,10 @@ module.exports = class ConfigsInjector { request.styleRefs = this.#getRouteStyleRefsToPreload(registryConfig.apps, slots, template.styleRefs); + if (request.ldeRelated) { + document = this.#removeProdTags(document); + } + return document; } @@ -246,4 +251,8 @@ module.exports = class ConfigsInjector { nrCode = nrCode.replace(/(.*)<\/script\s*>/s, '$1'); return this.#nrCustomClientJsWrapper.replace('%CONTENT%', nrCode); }; + + #removeProdTags(content) { + return content.replace(this.#markedProdTags, ''); + } }; diff --git a/ilc/server/tailor/configs-injector.spec.js b/ilc/server/tailor/configs-injector.spec.js index 5e773ac1..4d3df967 100644 --- a/ilc/server/tailor/configs-injector.spec.js +++ b/ilc/server/tailor/configs-injector.spec.js @@ -2,6 +2,7 @@ const chai = require('chai'); const sinon = require('sinon'); const _ = require('lodash'); const _fp = require('lodash/fp'); +const LZUTF8 = require('lzutf8'); const { context } = require('../context/context'); const ConfigsInjector = require('./configs-injector'); @@ -417,5 +418,54 @@ describe('configs injector', () => { }, ); }); + it('should remove marked tags for LDE if cookie is present', () => { + const overrideConfig = JSON.stringify({ someKey: 'someValue' }); + const encodedOverrideConfig = 'LZUTF8:' + LZUTF8.encodeBase64(LZUTF8.compress(overrideConfig)); + + context.run( + { + request: { + raw: { + url: 'test/a?test=15', + connection: { + encrypted: true, + }, + }, + hostname: 'test.com', + headers: { + cookie: `ILC-overrideConfig=${encodedOverrideConfig}`, + }, + }, + }, + () => { + const nrHeader = ``; + const configsInjector = new ConfigsInjector(newrelic); + const request = { registryConfig, ilcState: { locale: 'en-US' }, ldeRelated: true }; + const template = { + styleRefs: [], + content: + '' + + '' + + nrHeader + + '' + + 'Configs Injector`s test' + + '' + + '' + + '' + + '' + + '
Hi there! I am content.
' + + '' + + '', + }; + + const result = configsInjector.inject(request, template, { slots, reqUrl: '/test/route?a=15' }); + chai.expect(result).to.not.include(nrHeader); + }, + ); + }); }); });