Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate version that replaces Math.random with crypto #748

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?
Loading