1+ import { createHash } from 'node:crypto' ;
12import { performance } from 'node:perf_hooks' ;
23import type { PluginApi } from '@rock-js/config' ;
3- import type { FingerprintSources } from '@rock-js/tools' ;
4+ import type { FingerprintInputHash , FingerprintSources } from '@rock-js/tools' ;
45import {
56 color ,
67 intro ,
@@ -12,6 +13,25 @@ import {
1213 spinner ,
1314} from '@rock-js/tools' ;
1415
16+ const hashValue = ( value : string ) =>
17+ `[HASHED:${ createHash ( 'sha256' ) . update ( value ) . digest ( 'hex' ) . substring ( 0 , 8 ) } ]` ;
18+
19+ /**
20+ * Redacts sensitive environment variables from fingerprint sources by hashing their values
21+ */
22+ function redactSensitiveSources ( sources : FingerprintInputHash [ ] ) {
23+ return sources . map ( ( source ) => {
24+ if ( source . key === 'json:env' && 'json' in source ) {
25+ const env = source . json as Record < string , string > ;
26+ const redactedEnv = Object . fromEntries (
27+ Object . entries ( env ) . map ( ( [ key , value ] ) => [ key , hashValue ( value ) ] ) ,
28+ ) ;
29+ return { ...source , json : redactedEnv } ;
30+ }
31+ return source ;
32+ } ) ;
33+ }
34+
1535type NativeFingerprintCommandOptions = {
1636 platform : 'ios' | 'android' ;
1737 raw ?: boolean ;
@@ -39,7 +59,9 @@ export async function nativeFingerprintCommand(
3959 JSON . stringify (
4060 {
4161 hash : fingerprint . hash ,
42- sources : fingerprint . inputs . filter ( ( source ) => source . hash != null ) ,
62+ sources : redactSensitiveSources (
63+ fingerprint . inputs . filter ( ( source ) => source . hash != null ) ,
64+ ) ,
4365 } ,
4466 null ,
4567 2 ,
@@ -69,7 +91,9 @@ export async function nativeFingerprintCommand(
6991 logger . debug (
7092 'Sources:' ,
7193 JSON . stringify (
72- fingerprint . inputs . filter ( ( source ) => source . hash != null ) ,
94+ redactSensitiveSources (
95+ fingerprint . inputs . filter ( ( source ) => source . hash != null ) ,
96+ ) ,
7397 null ,
7498 2 ,
7599 ) ,
0 commit comments