Skip to content

Commit

Permalink
Generate version that replaces Math.random with crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
t2t2 committed Mar 25, 2024
1 parent b44424f commit b082a41
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 9 deletions.
66 changes: 57 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"scripts": {
"compile": "npm run --ws compile --",
"generate:security-theater": "node ./scripts/security-theater-generator.mjs",
"lint": "eslint --ignore-path .gitignore packages/*/src/ packages/*/test/ packages/*/integration-tests/",
"lint:markdown": "markdownlint *.md docs/*.md",
"lint:fix": "eslint --ignore-path .gitignore --fix packages/*/src/ packages/*/test/ packages/*/integration-tests/",
Expand Down Expand Up @@ -47,6 +48,7 @@
"dotenv": "^16.3.1",
"eslint": "^8.45.0",
"eslint-plugin-header": "^3.1.1",
"magic-string": "^0.30.8",
"typescript": "^5.1.6"
}
}
26 changes: 26 additions & 0 deletions scripts/security-theater-generator.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2024 Splunk Inc.
Licensed 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.
*/

import { readFile, writeFile } from 'node:fs/promises';
import MagicString from 'magic-string';

const source = await readFile('packages/web/dist/artifacts/splunk-otel-web.js', { encoding: 'utf-8' });

const string = new MagicString(source);
string.replaceAll('Math.random()', '(crypto.getRandomValues(new Uint32Array(1))[0]/Math.pow(2,32))');

writeFile('packages/web/dist/artifacts/splunk-otel-web-security-theater-edition.js', string.toString());
// future (rollup plugin?) - can we do something with sourcemap from string.generateMap?

0 comments on commit b082a41

Please sign in to comment.