utils.tsx 4.8 KB

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