utils.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import {t} from 'sentry/locale';
  2. import type {Rule, SourceSuggestion} from './types';
  3. import {MethodType, RuleType, SourceSuggestionType} from './types';
  4. function getRuleLabel(type: RuleType) {
  5. switch (type) {
  6. case RuleType.ANYTHING:
  7. return t('Anything');
  8. case RuleType.IMEI:
  9. return t('IMEI numbers');
  10. case RuleType.MAC:
  11. return t('MAC addresses');
  12. case RuleType.EMAIL:
  13. return t('Email addresses');
  14. case RuleType.PEMKEY:
  15. return t('PEM keys');
  16. case RuleType.URLAUTH:
  17. return t('Auth in URLs');
  18. case RuleType.USSSN:
  19. return t('US social security numbers');
  20. case RuleType.USER_PATH:
  21. return t('Usernames in filepaths');
  22. case RuleType.UUID:
  23. return t('UUIDs');
  24. case RuleType.CREDITCARD:
  25. return t('Credit card numbers');
  26. case RuleType.PASSWORD:
  27. return t('Password fields');
  28. case RuleType.IP:
  29. return t('IP addresses');
  30. case RuleType.PATTERN:
  31. return t('Regex matches');
  32. default:
  33. return '';
  34. }
  35. }
  36. function getMethodLabel(type: MethodType) {
  37. switch (type) {
  38. case MethodType.MASK:
  39. return {
  40. label: t('Mask'),
  41. description: t('Replace with ****'),
  42. };
  43. case MethodType.HASH:
  44. return {
  45. label: t('Hash'),
  46. description: t('Replace with DEADBEEF'),
  47. };
  48. case MethodType.REMOVE:
  49. return {
  50. label: t('Remove'),
  51. description: t('Replace with null'),
  52. };
  53. case MethodType.REPLACE:
  54. return {
  55. label: t('Replace'),
  56. description: t('Replace with Placeholder'),
  57. };
  58. default:
  59. return {
  60. label: '',
  61. };
  62. }
  63. }
  64. const binarySuggestions: Array<SourceSuggestion> = [
  65. {
  66. type: SourceSuggestionType.BINARY,
  67. value: '&&',
  68. },
  69. {
  70. type: SourceSuggestionType.BINARY,
  71. value: '||',
  72. },
  73. ];
  74. const unarySuggestions: Array<SourceSuggestion> = [
  75. {
  76. type: SourceSuggestionType.UNARY,
  77. value: '!',
  78. },
  79. ];
  80. const valueSuggestions: Array<SourceSuggestion> = [
  81. {
  82. type: SourceSuggestionType.VALUE,
  83. value: '**',
  84. description: t('all default PII fields'),
  85. },
  86. {
  87. type: SourceSuggestionType.VALUE,
  88. value: 'password',
  89. description: t('attributes named "password"'),
  90. },
  91. {
  92. type: SourceSuggestionType.VALUE,
  93. value: '$error.value',
  94. description: t('the exception value'),
  95. },
  96. {
  97. type: SourceSuggestionType.VALUE,
  98. value: '$message',
  99. description: t('the log message'),
  100. },
  101. {
  102. type: SourceSuggestionType.VALUE,
  103. value: 'extra.MyValue',
  104. description: t('the key "MyValue" in "Additional Data"'),
  105. },
  106. {
  107. type: SourceSuggestionType.VALUE,
  108. value: 'extra.**',
  109. description: t('everything in "Additional Data"'),
  110. },
  111. {
  112. type: SourceSuggestionType.VALUE,
  113. value: '$http.headers.x-custom-token',
  114. description: t('the X-Custom-Token HTTP header'),
  115. },
  116. {
  117. type: SourceSuggestionType.VALUE,
  118. value: '$user.ip_address',
  119. description: t('the user IP address'),
  120. },
  121. {
  122. type: SourceSuggestionType.VALUE,
  123. value: '$frame.vars.foo',
  124. description: t('the local variable "foo"'),
  125. },
  126. {
  127. type: SourceSuggestionType.VALUE,
  128. value: 'contexts.device.timezone',
  129. description: t('the timezone in the device context'),
  130. },
  131. {
  132. type: SourceSuggestionType.VALUE,
  133. value: 'tags.server_name',
  134. description: t('the tag "server_name"'),
  135. },
  136. {
  137. type: SourceSuggestionType.VALUE,
  138. value: '$attachments.**',
  139. description: t('all attachments'),
  140. },
  141. {
  142. type: SourceSuggestionType.VALUE,
  143. value: "$attachments.'logfile.txt'",
  144. description: t('all attachments named "logfile.txt"'),
  145. },
  146. {
  147. type: SourceSuggestionType.VALUE,
  148. value: '$minidump',
  149. description: t('the entire minidump of a native crash report'),
  150. },
  151. {
  152. type: SourceSuggestionType.VALUE,
  153. value: '$minidump.heap_memory',
  154. description: t('the heap memory region in a native crash report'),
  155. },
  156. {
  157. type: SourceSuggestionType.VALUE,
  158. value: 'code_file',
  159. description: t('the pathname of a code module in a native crash report'),
  160. },
  161. {
  162. type: SourceSuggestionType.VALUE,
  163. value: 'debug_file',
  164. description: t('the pathname of a debug module in a native crash report'),
  165. },
  166. ];
  167. export {
  168. binarySuggestions,
  169. getMethodLabel,
  170. getRuleLabel,
  171. unarySuggestions,
  172. valueSuggestions,
  173. };
  174. export function getRuleDescription(rule: Rule) {
  175. const {method, type, source} = rule;
  176. const methodLabel = getMethodLabel(method);
  177. const typeLabel = getRuleLabel(type);
  178. const descriptionDetails: Array<string> = [];
  179. descriptionDetails.push(`[${methodLabel.label}]`);
  180. descriptionDetails.push(
  181. rule.type === RuleType.PATTERN ? `[${rule.pattern}]` : `[${typeLabel}]`
  182. );
  183. if (rule.method === MethodType.REPLACE && rule.placeholder) {
  184. descriptionDetails.push(`with [${rule.placeholder}]`);
  185. }
  186. return `${descriptionDetails.join(' ')} ${t('from')} [${source}]`;
  187. }