index.tsx 3.7 KB

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