index.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import {RouteComponentProps} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import Button from 'sentry/components/button';
  4. import {Panel, PanelBody, PanelHeader, PanelItem} from 'sentry/components/panels';
  5. import {t, tct} from 'sentry/locale';
  6. import {ProjectKey} from 'sentry/types';
  7. import recreateRoute from 'sentry/utils/recreateRoute';
  8. import routeTitleGen from 'sentry/utils/routeTitle';
  9. import AsyncView from 'sentry/views/asyncView';
  10. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  11. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  12. import ReportUri from 'sentry/views/settings/projectSecurityHeaders/reportUri';
  13. type Props = RouteComponentProps<{orgId: string; projectId: string}, {}>;
  14. type State = {
  15. keyList: null | ProjectKey[];
  16. } & AsyncView['state'];
  17. export default class ProjectSecurityHeaders extends AsyncView<Props, State> {
  18. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  19. const {orgId, projectId} = this.props.params;
  20. return [['keyList', `/projects/${orgId}/${projectId}/keys/`]];
  21. }
  22. getTitle() {
  23. const {projectId} = this.props.params;
  24. return routeTitleGen(t('Security Headers'), projectId, false);
  25. }
  26. getReports() {
  27. return [
  28. {
  29. name: 'Content Security Policy (CSP)',
  30. url: recreateRoute('csp/', this.props),
  31. },
  32. {
  33. name: 'Certificate Transparency (Expect-CT)',
  34. url: recreateRoute('expect-ct/', this.props),
  35. },
  36. {
  37. name: 'HTTP Public Key Pinning (HPKP)',
  38. url: recreateRoute('hpkp/', this.props),
  39. },
  40. ];
  41. }
  42. renderBody() {
  43. const {params} = this.props;
  44. const {keyList} = this.state;
  45. if (keyList === null) {
  46. return null;
  47. }
  48. return (
  49. <div>
  50. <SettingsPageHeader title={t('Security Header Reports')} />
  51. <ReportUri keyList={keyList} projectId={params.projectId} orgId={params.orgId} />
  52. <Panel>
  53. <PanelHeader>{t('Additional Configuration')}</PanelHeader>
  54. <PanelBody withPadding>
  55. <TextBlock style={{marginBottom: 20}}>
  56. {tct(
  57. 'In addition to the [key_param] parameter, you may also pass the following within the querystring for the report URI:',
  58. {
  59. key_param: <code>sentry_key</code>,
  60. }
  61. )}
  62. </TextBlock>
  63. <table className="table" style={{marginBottom: 0}}>
  64. <tbody>
  65. <tr>
  66. <th style={{padding: '8px 5px'}}>sentry_environment</th>
  67. <td style={{padding: '8px 5px'}}>
  68. {t('The environment name (e.g. production)')}.
  69. </td>
  70. </tr>
  71. <tr>
  72. <th style={{padding: '8px 5px'}}>sentry_release</th>
  73. <td style={{padding: '8px 5px'}}>
  74. {t('The version of the application.')}
  75. </td>
  76. </tr>
  77. </tbody>
  78. </table>
  79. </PanelBody>
  80. </Panel>
  81. <Panel>
  82. <PanelHeader>{t('Supported Formats')}</PanelHeader>
  83. <PanelBody>
  84. {this.getReports().map(({name, url}) => (
  85. <ReportItem key={url}>
  86. <HeaderName>{name}</HeaderName>
  87. <Button to={url} priority="primary">
  88. {t('Instructions')}
  89. </Button>
  90. </ReportItem>
  91. ))}
  92. </PanelBody>
  93. </Panel>
  94. </div>
  95. );
  96. }
  97. }
  98. const ReportItem = styled(PanelItem)`
  99. align-items: center;
  100. justify-content: space-between;
  101. `;
  102. const HeaderName = styled('span')`
  103. font-size: 1.2em;
  104. `;