hof 19.14.2 → 20.0.0-beta.2
Sign up to get free protection for your applications and to get access to all the features.
- package/.nyc_output/65af88d9-aebe-4d1b-a21d-6fbf7f2bbda4.json +1 -0
- package/.nyc_output/processinfo/65af88d9-aebe-4d1b-a21d-6fbf7f2bbda4.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/.vscode/settings.json +6 -0
- package/components/date/index.js +26 -35
- package/components/date/templates/date.html +15 -12
- package/components/emailer/index.js +41 -49
- package/components/summary/index.js +0 -18
- package/config/hof-defaults.js +2 -4
- package/controller/base-controller.js +8 -26
- package/controller/controller.js +45 -2
- package/frontend/govuk-template/build/config.js +3 -3
- package/frontend/govuk-template/build/govuk_template.html +104 -0
- package/frontend/govuk-template/build/index.js +2 -2
- package/frontend/govuk-template/govuk_template_generated.html +104 -0
- package/frontend/govuk-template/index.js +4 -4
- package/frontend/template-mixins/mixins/template-mixins.js +20 -9
- package/frontend/template-mixins/partials/forms/checkbox-group.html +38 -0
- package/frontend/template-mixins/partials/forms/checkbox.html +4 -4
- package/frontend/template-mixins/partials/forms/input-submit.html +1 -1
- package/frontend/template-mixins/partials/forms/input-text-date.html +37 -0
- package/frontend/template-mixins/partials/forms/input-text-group.html +12 -9
- package/frontend/template-mixins/partials/forms/option-group.html +33 -26
- package/frontend/template-mixins/partials/forms/select.html +10 -5
- package/frontend/template-mixins/partials/forms/textarea-group.html +15 -6
- package/frontend/template-mixins/partials/mixins/panel.html +4 -4
- package/frontend/template-partials/translations/src/en/errors.json +0 -12
- package/frontend/template-partials/views/accessibility.html +4 -4
- package/frontend/template-partials/views/cookies.html +1 -1
- package/frontend/template-partials/views/layout.html +22 -22
- package/frontend/template-partials/views/partials/back.html +1 -1
- package/frontend/template-partials/views/partials/bullet-list.html +1 -1
- package/frontend/template-partials/views/partials/confirmation-alert.html +4 -3
- package/frontend/template-partials/views/partials/continue.html +1 -1
- package/frontend/template-partials/views/partials/cookie-banner.html +27 -24
- package/frontend/template-partials/views/partials/cookie-settings-radio.html +6 -6
- package/frontend/template-partials/views/partials/external-link.html +1 -1
- package/frontend/template-partials/views/partials/form.html +1 -1
- package/frontend/template-partials/views/partials/maincontent-left.html +4 -4
- package/frontend/template-partials/views/partials/navigation.html +7 -6
- package/frontend/template-partials/views/partials/session-cookies-table.html +6 -6
- package/frontend/template-partials/views/partials/table.html +7 -7
- package/frontend/template-partials/views/partials/validation-list.html +2 -2
- package/frontend/template-partials/views/partials/validation-summary.html +14 -13
- package/frontend/template-partials/views/session-timeout.html +1 -1
- package/frontend/themes/gov-uk/client-js/cookieSettings.js +1 -1
- package/frontend/themes/gov-uk/client-js/govuk-cookies.js +122 -0
- package/frontend/themes/gov-uk/client-js/index.js +5 -0
- package/frontend/themes/gov-uk/client-js/skip-to-main.js +18 -0
- package/frontend/themes/gov-uk/styles/_cookie-banner.scss +51 -1
- package/frontend/themes/gov-uk/styles/modules/_validation.scss +3 -3
- package/frontend/toolkit/assets/javascript/character-count.js +4 -4
- package/frontend/toolkit/assets/stylesheets/modules/_validation.scss +3 -3
- package/index.js +5 -5
- package/lib/router.js +1 -2
- package/lib/settings.js +17 -2
- package/middleware/errors.js +0 -32
- package/middleware/index.js +1 -2
- package/package.json +7 -6
- package/sandbox/.env +1 -0
- package/sandbox/apps/sandbox/fields.js +24 -11
- package/sandbox/apps/sandbox/index.js +5 -1
- package/sandbox/apps/sandbox/translations/en/default.json +203 -0
- package/sandbox/apps/sandbox/translations/src/en/fields.json +9 -6
- package/sandbox/apps/sandbox/translations/src/en/journey.json +4 -1
- package/sandbox/apps/sandbox/translations/src/en/pages.json +2 -29
- package/sandbox/apps/sandbox/translations/src/en/validation.json +1 -1
- package/sandbox/assets/js/index.js +1 -1
- package/sandbox/assets/scss/app.scss +68 -16
- package/sandbox/package.json +4 -1
- package/sandbox/public/css/app.css +9444 -0
- package/sandbox/public/images/icons/icon-caret-left.png +0 -0
- package/sandbox/public/images/icons/icon-complete.png +0 -0
- package/sandbox/public/images/icons/icon-cross-remove-sign.png +0 -0
- package/sandbox/public/js/bundle.js +35644 -0
- package/sandbox/server.js +0 -5
- package/sandbox/yarn.lock +767 -0
- package/utilities/helpers/index.js +1 -16
- package/wizard/index.js +0 -1
- package/config/rate-limits.js +0 -20
- package/config/sanitisation-rules.js +0 -29
- package/frontend/govuk-template/govuk_template.html +0 -109
- package/frontend/template-partials/views/rate-limit-error.html +0 -10
- package/frontend/themes/gov-uk/views/partials/form.html +0 -9
- package/frontend/themes/gov-uk/views/partials/forms/option-group.html +0 -28
- package/frontend/themes/gov-uk/views/partials/mixins/panel.html +0 -3
- package/frontend/themes/gov-uk/views/partials/validation-summary.html +0 -24
- package/middleware/rate-limiter.js +0 -96
- package/sandbox/apps/sandbox/views/confirmation.html +0 -15
@@ -94,7 +94,7 @@ module.exports = class Helpers {
|
|
94
94
|
/**
|
95
95
|
* utility function which returns undefined on
|
96
96
|
* failed translations instead of returning the key
|
97
|
-
* @param {Function} translate - the translate
|
97
|
+
* @param {Function} translate - the translate funtion
|
98
98
|
* @param {String} key - the key to translate
|
99
99
|
* @returns {String|undefined} the string result if successful, undefined if not
|
100
100
|
*/
|
@@ -131,19 +131,4 @@ module.exports = class Helpers {
|
|
131
131
|
`pages.${key}.header`
|
132
132
|
]) || key;
|
133
133
|
}
|
134
|
-
/**
|
135
|
-
* utility function which returns true or false on
|
136
|
-
* forks depending on whether a value exists on the page
|
137
|
-
* @param {Object} req - an http request object
|
138
|
-
* @param {Object} res - an http response object
|
139
|
-
* @param {Function|Object} condition - a field condition that is either a function or object
|
140
|
-
* @returns {Boolean} the boolean result of whether a field value is set on the page or session for a fork
|
141
|
-
*/
|
142
|
-
static isFieldValueInPageOrSessionValid(req, res, condition) {
|
143
|
-
return _.isFunction(condition) ?
|
144
|
-
condition(req, res) :
|
145
|
-
condition.value === (req.form.values[condition.field] ||
|
146
|
-
(!Object.keys(req.form.values).includes(condition.field) &&
|
147
|
-
_.get(req, `form.historicalValues[${condition.field}]`)));
|
148
|
-
}
|
149
134
|
};
|
package/wizard/index.js
CHANGED
@@ -69,7 +69,6 @@ const Wizard = (steps, fields, setts) => {
|
|
69
69
|
options.confirmStep = settings.confirmStep;
|
70
70
|
options.clearSession = options.clearSession || false;
|
71
71
|
options.fieldsConfig = _.cloneDeep(fields);
|
72
|
-
options.sanitiseInputs = settings.sanitiseInputs;
|
73
72
|
|
74
73
|
options.defaultFormatters = [].concat(settings.formatters);
|
75
74
|
|
package/config/rate-limits.js
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
|
2
|
-
module.exports = {
|
3
|
-
rateLimits: {
|
4
|
-
env: process.env.NODE_ENV,
|
5
|
-
requests: {
|
6
|
-
active: false,
|
7
|
-
windowSizeInMinutes: 5,
|
8
|
-
maxWindowRequestCount: 100,
|
9
|
-
windowLogIntervalInMinutes: 1,
|
10
|
-
errCode: 'DDOS_RATE_LIMIT'
|
11
|
-
},
|
12
|
-
submissions: {
|
13
|
-
active: false,
|
14
|
-
windowSizeInMinutes: 10,
|
15
|
-
maxWindowRequestCount: 1,
|
16
|
-
windowLogIntervalInMinutes: 1,
|
17
|
-
errCode: 'SUBMISSION_RATE_LIMIT'
|
18
|
-
}
|
19
|
-
}
|
20
|
-
};
|
@@ -1,29 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
/* eslint no-process-env: "off" */
|
3
|
-
|
4
|
-
const sanitisationBlacklistArray = {
|
5
|
-
// Input will be sanitised using the below rules
|
6
|
-
// The key is what we're sanitising out
|
7
|
-
// The regex is the rule we used to find them (note some dictate repeating characters)
|
8
|
-
// And the replace is what we're replacing that pattern with. Usually nothing sometimes a
|
9
|
-
// single character or sometimes a single character followed by a "-"
|
10
|
-
'/*': { regex: '\/\\*', replace: '-' },
|
11
|
-
'*/': { regex: '\\*\\/', replace: '-' },
|
12
|
-
'|': { regex: '\\|', replace: '-' },
|
13
|
-
'&&': { regex: '&&+', replace: '&' },
|
14
|
-
'@@': { regex: '@@+', replace: '@' },
|
15
|
-
'/..;/': { regex: '/\\.\\.;/', replace: '-' }, // Purposely input before ".." as they conflict
|
16
|
-
'..': { regex: '\\.\\.+', replace: '.' },
|
17
|
-
'/etc/passwd': { regex: '\/etc\/passwd', replace: '-' },
|
18
|
-
'c:\\': { regex: 'c:\\\\', replace: '-' },
|
19
|
-
'cmd.exe': { regex: 'cmd\\.exe', replace: '-' },
|
20
|
-
'<': { regex: '<', replace: '<-' },
|
21
|
-
'>': { regex: '>', replace: '>-' },
|
22
|
-
'[': { regex: '\\[+', replace: '[-' },
|
23
|
-
']': { regex: '\\]+', replace: ']-' },
|
24
|
-
'~': { regex: '~', replace: '~-' },
|
25
|
-
'&#': { regex: '&#', replace: '&#-' },
|
26
|
-
'%U': { regex: '%U', replace: '%U-' }
|
27
|
-
};
|
28
|
-
|
29
|
-
module.exports = sanitisationBlacklistArray;
|
@@ -1,109 +0,0 @@
|
|
1
|
-
|
2
|
-
<!DOCTYPE html>
|
3
|
-
<!--[if lt IE 9]><html class="lte-ie8" lang="{{htmlLang}}"><![endif]-->
|
4
|
-
<!--[if gt IE 8]><!--><html lang="{{htmlLang}}"><!--<![endif]-->
|
5
|
-
<head>
|
6
|
-
<meta charset="utf-8" />
|
7
|
-
<title>{{$pageTitle}}{{/pageTitle}}</title>
|
8
|
-
|
9
|
-
<!--[if gt IE 8]><!--><link rel="stylesheet" media="screen" href="{{govukAssetPath}}stylesheets/govuk-template.css?0.26.0"/><!--<![endif]-->
|
10
|
-
<!--[if IE 6]><link rel="stylesheet" media="screen" href="{{govukAssetPath}}stylesheets/govuk-template-ie6.css?0.26.0"/><![endif]-->
|
11
|
-
<!--[if IE 7]><link rel="stylesheet" media="screen" href="{{govukAssetPath}}stylesheets/govuk-template-ie7.css?0.26.0"/><![endif]-->
|
12
|
-
<!--[if IE 8]><link rel="stylesheet" media="screen" href="{{govukAssetPath}}stylesheets/govuk-template-ie8.css?0.26.0"/><![endif]-->
|
13
|
-
<link rel="stylesheet" media="print" href="{{govukAssetPath}}stylesheets/govuk-template-print.css?0.26.0"/>
|
14
|
-
|
15
|
-
<link rel="stylesheet" media="all" href="{{govukAssetPath}}stylesheets/fonts.css?0.26.0"/>
|
16
|
-
<!--[if lt IE 9]><script src="{{govukAssetPath}}javascripts/ie.js?0.26.0"></script><![endif]-->
|
17
|
-
|
18
|
-
<link rel="shortcut icon" href="{{govukAssetPath}}images/favicon.ico?0.26.0" type="image/x-icon" />
|
19
|
-
|
20
|
-
<link rel="mask-icon" href="{{govukAssetPath}}images/gov.uk_logotype_crown.svg?0.26.0" color="#0b0c0c">
|
21
|
-
<link rel="apple-touch-icon" sizes="180x180" href="{{govukAssetPath}}images/apple-touch-icon-180x180.png?0.26.0">
|
22
|
-
<link rel="apple-touch-icon" sizes="167x167" href="{{govukAssetPath}}images/apple-touch-icon-167x167.png?0.26.0">
|
23
|
-
<link rel="apple-touch-icon" sizes="152x152" href="{{govukAssetPath}}images/apple-touch-icon-152x152.png?0.26.0">
|
24
|
-
<link rel="apple-touch-icon" href="{{govukAssetPath}}images/apple-touch-icon.png?0.26.0">
|
25
|
-
|
26
|
-
|
27
|
-
<meta name="theme-color" content="#0b0c0c" />
|
28
|
-
|
29
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
30
|
-
|
31
|
-
{{$head}}{{/head}}
|
32
|
-
|
33
|
-
|
34
|
-
<meta property="og:image" content="{{govukAssetPath}}images/opengraph-image.png?0.26.0">
|
35
|
-
</head>
|
36
|
-
|
37
|
-
<body class="{{$bodyClasses}}{{/bodyClasses}}">
|
38
|
-
<script {{#nonce}}nonce="{{nonce}}"{{/nonce}}>document.body.className = ((document.body.className) ? document.body.className + ' js-enabled' : 'js-enabled');</script>
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
<div id="skiplink-container">
|
43
|
-
<div>
|
44
|
-
<a href="#content" class="skiplink">{{$skipLinkMessage}}Skip to main content{{/skipLinkMessage}}</a>
|
45
|
-
</div>
|
46
|
-
</div>
|
47
|
-
|
48
|
-
<div id="global-cookie-message">
|
49
|
-
|
50
|
-
{{$cookieMessage}}{{/cookieMessage}}
|
51
|
-
|
52
|
-
</div>
|
53
|
-
|
54
|
-
|
55
|
-
<header role="banner" id="global-header" class="{{$headerClass}}{{/headerClass}}">
|
56
|
-
<div class="header-wrapper">
|
57
|
-
<div class="header-global">
|
58
|
-
<div class="header-logo">
|
59
|
-
<a href="{{$homepageUrl}}https://www.gov.uk{{/homepageUrl}}" title="{{$logoLinkTitle}}Go to the GOV.UK homepage{{/logoLinkTitle}}" id="logo" class="content" data-module="track-click" data-track-category="homeLinkClicked" data-track-action="homeHeader">
|
60
|
-
<img src="{{govukAssetPath}}images/gov.uk_logotype_crown_invert_trans.png?0.26.0" width="36" height="32" alt=""> {{$globalHeaderText}}GOV.UK{{/globalHeaderText}}
|
61
|
-
</a>
|
62
|
-
</div>
|
63
|
-
{{$insideHeader}}{{/insideHeader}}
|
64
|
-
</div>
|
65
|
-
{{$propositionHeader}}{{/propositionHeader}}
|
66
|
-
</div>
|
67
|
-
</header>
|
68
|
-
|
69
|
-
|
70
|
-
{{$afterHeader}}{{/afterHeader}}
|
71
|
-
|
72
|
-
<div id="global-header-bar"></div>
|
73
|
-
|
74
|
-
{{$main}}{{/main}}
|
75
|
-
|
76
|
-
<footer class="group js-footer" id="footer" role="contentinfo">
|
77
|
-
|
78
|
-
<div class="footer-wrapper">
|
79
|
-
{{$footerTop}}{{/footerTop}}
|
80
|
-
|
81
|
-
<div class="footer-meta">
|
82
|
-
<div class="footer-meta-inner">
|
83
|
-
{{$footerSupportLinks}}{{/footerSupportLinks}}
|
84
|
-
|
85
|
-
<div class="open-government-licence">
|
86
|
-
<p class="logo"><a href="https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/" rel="license">Open Government Licence</a></p>
|
87
|
-
|
88
|
-
{{$licenceMessage}}<p>All content is available under the <a href="https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/" rel="license">Open Government Licence v3.0</a>, except where otherwise stated</p>{{/licenceMessage}}
|
89
|
-
|
90
|
-
</div>
|
91
|
-
</div>
|
92
|
-
|
93
|
-
<div class="copyright">
|
94
|
-
<a href="https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/">{{$crownCopyrightMessage}}© Crown copyright{{/crownCopyrightMessage}}</a>
|
95
|
-
</div>
|
96
|
-
</div>
|
97
|
-
</div>
|
98
|
-
</footer>
|
99
|
-
|
100
|
-
<div id="global-app-error" class="app-error hidden"></div>
|
101
|
-
|
102
|
-
<script src="{{govukAssetPath}}javascripts/govuk-template.js?0.26.0"></script>
|
103
|
-
|
104
|
-
{{$bodyEnd}}{{/bodyEnd}}
|
105
|
-
|
106
|
-
|
107
|
-
<script {{#nonce}}nonce="{{nonce}}"{{/nonce}}>if (typeof window.GOVUK === 'undefined') document.body.className = document.body.className.replace('js-enabled', '');</script>
|
108
|
-
</body>
|
109
|
-
</html>
|
@@ -1,10 +0,0 @@
|
|
1
|
-
{{<layout}}
|
2
|
-
{{$header}}
|
3
|
-
{{content.title}}
|
4
|
-
{{/header}}
|
5
|
-
{{$content}}
|
6
|
-
<p>{{content.message}}</p>
|
7
|
-
<p>{{content.preTimeToWait}}{{content.timeToWait}}{{content.postTimeToWait}}</p>
|
8
|
-
<a href="/" class="button" role="button">{{#t}}buttons.try-again{{/t}}</a>
|
9
|
-
{{/content}}
|
10
|
-
{{/layout}}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
<form action="" method="POST" {{$encoding}}{{/encoding}} autocomplete="off" novalidate="true" spellcheck="false">
|
2
|
-
{{$intro}}
|
3
|
-
{{#intro}}<p>{{intro}}</p>{{/intro}}
|
4
|
-
{{/intro}}
|
5
|
-
{{$form}}{{/form}}
|
6
|
-
{{#csrf-token}}
|
7
|
-
<input type="hidden" name="x-csrf-token" value="{{csrf-token}}" />
|
8
|
-
{{/csrf-token}}
|
9
|
-
</form>
|
@@ -1,28 +0,0 @@
|
|
1
|
-
<div id="{{key}}-group" class="form-group{{#className}} {{className}} {{/className}}{{#formGroupClassName}} {{formGroupClassName}}{{/formGroupClassName}}{{#error}} validation-error{{/error}}">
|
2
|
-
<fieldset role="{{role}}"{{#ariaRequired}} aria-required="true"{{/ariaRequired}}{{#hint}} aria-describedby="{{key}}-hint"{{/hint}}>
|
3
|
-
<legend>
|
4
|
-
<span{{#legendClassName}} class="{{legendClassName}}"{{/legendClassName}}>{{legend}}</span>
|
5
|
-
{{#hint}}<span id="{{key}}-hint" class="form-hint">{{hint}}</span>{{/hint}}
|
6
|
-
{{#error}}<span id="{{key}}-error" class="error-message">{{error.message}}</span>{{/error}}
|
7
|
-
</legend>
|
8
|
-
{{#options}}
|
9
|
-
<div class="multiple-choice">
|
10
|
-
<input
|
11
|
-
type="{{type}}"
|
12
|
-
name="{{key}}"
|
13
|
-
id="{{key}}-{{value}}"
|
14
|
-
value="{{value}}"
|
15
|
-
{{#toggle}} data-toggle="{{toggle}}"{{/toggle}}
|
16
|
-
{{#selected}} checked="checked"{{/selected}}
|
17
|
-
{{^error}}{{#optionHint}} aria-describedby="{{key}}-{{value}}-hint"{{/optionHint}}{{^optionHint}}{{#hint}} aria-describedby="{{key}}-hint"{{/hint}}{{/optionHint}}{{/error}}
|
18
|
-
{{#error}} aria-describedby="{{key}}-error" aria-invalid="true"{{/error}}
|
19
|
-
>
|
20
|
-
<label class="block-label" for="{{key}}-{{value}}">
|
21
|
-
{{{label}}}
|
22
|
-
{{#optionHint}}<span id="{{key}}-{{value}}-hint" class="form-hint">{{optionHint}}</span>{{/optionHint}}
|
23
|
-
</label>
|
24
|
-
</div>
|
25
|
-
{{#renderChild}}{{/renderChild}}
|
26
|
-
{{/options}}
|
27
|
-
</fieldset>
|
28
|
-
</div>
|
@@ -1,24 +0,0 @@
|
|
1
|
-
{{#errorlist.length}}
|
2
|
-
<div class="validation-summary error-summary" tabindex="-1">
|
3
|
-
{{$errorlist-title}}
|
4
|
-
|
5
|
-
{{#errorLength.single}}
|
6
|
-
<h2>{{#t}}errorlist.title.single{{/t}}</h2>
|
7
|
-
{{/errorLength.single}}
|
8
|
-
{{#errorLength.multiple}}
|
9
|
-
<h2>{{#t}}errorlist.title.multiple{{/t}}</h2>
|
10
|
-
{{/errorLength.multiple}}
|
11
|
-
|
12
|
-
{{/errorlist-title}}
|
13
|
-
|
14
|
-
{{<partials-validation-list}}
|
15
|
-
{{$validation-list}}
|
16
|
-
{{#errorlist}}
|
17
|
-
{{#message}}
|
18
|
-
<li><a href="#{{key}}">{{ message }}</a></li>
|
19
|
-
{{/message}}
|
20
|
-
{{/errorlist}}
|
21
|
-
{{/validation-list}}
|
22
|
-
{{/partials-validation-list}}
|
23
|
-
</div>
|
24
|
-
{{/errorlist.length}}
|
@@ -1,96 +0,0 @@
|
|
1
|
-
|
2
|
-
const moment = require('moment');
|
3
|
-
const redis = require('redis');
|
4
|
-
|
5
|
-
module.exports = (options, rateLimitType) => {
|
6
|
-
const logger = options.logger || { log: (func, msg) => console[func](msg) };
|
7
|
-
const rateLimits = options.rateLimits[rateLimitType];
|
8
|
-
const timestampName = `${rateLimitType}TimeStamp`;
|
9
|
-
const countName = `${rateLimitType}Count`;
|
10
|
-
|
11
|
-
const WINDOW_SIZE_IN_MINUTES = rateLimits.windowSizeInMinutes;
|
12
|
-
const MAX_WINDOW_REQUEST_COUNT = rateLimits.maxWindowRequestCount;
|
13
|
-
const WINDOW_LOG_INTERVAL_IN_MINUTES = rateLimits.windowLogIntervalInMinutes;
|
14
|
-
const ERROR_CODE = rateLimits.errCode;
|
15
|
-
|
16
|
-
return async (req, res, next) => {
|
17
|
-
const redisClient = redis.createClient();
|
18
|
-
|
19
|
-
// check that redis client exists
|
20
|
-
if (!redisClient) {
|
21
|
-
logger.log('error', 'Redis client does not exist!');
|
22
|
-
return next();
|
23
|
-
}
|
24
|
-
|
25
|
-
const closeConnection = async err => {
|
26
|
-
await redisClient.quit();
|
27
|
-
return next(err);
|
28
|
-
};
|
29
|
-
|
30
|
-
try {
|
31
|
-
// fetch records of current user using IP address, returns null when no record is found
|
32
|
-
return await redisClient.get(req.ip, async (err, record) => {
|
33
|
-
if (err) {
|
34
|
-
logger.log('error', `Error with requesting redis session for rate limiting: ${err}`);
|
35
|
-
return await closeConnection();
|
36
|
-
}
|
37
|
-
const currentRequestTime = moment();
|
38
|
-
const windowStartTimestamp = moment().subtract(WINDOW_SIZE_IN_MINUTES, 'minutes').unix();
|
39
|
-
let oldRecord = false;
|
40
|
-
let data;
|
41
|
-
// if no record is found , create a new record for user and store to redis
|
42
|
-
if (record) {
|
43
|
-
data = JSON.parse(record);
|
44
|
-
oldRecord = data[data.length - 1][timestampName] < windowStartTimestamp;
|
45
|
-
}
|
46
|
-
|
47
|
-
if (!record || oldRecord) {
|
48
|
-
const newRecord = [];
|
49
|
-
const requestLog = {
|
50
|
-
[timestampName]: currentRequestTime.unix(),
|
51
|
-
[countName]: 1
|
52
|
-
};
|
53
|
-
newRecord.push(requestLog);
|
54
|
-
await redisClient.set(req.ip, JSON.stringify(newRecord));
|
55
|
-
return await closeConnection();
|
56
|
-
}
|
57
|
-
// if record is found, parse it's value and calculate number of requests users has made within the last window
|
58
|
-
const requestsWithinWindow = data.filter(entry => entry[timestampName] > windowStartTimestamp);
|
59
|
-
|
60
|
-
const totalWindowRequestsCount = requestsWithinWindow.reduce((accumulator, entry) => {
|
61
|
-
return accumulator + entry[countName];
|
62
|
-
}, 0);
|
63
|
-
|
64
|
-
if (!options.rateLimits.env || options.rateLimits.env === 'development') {
|
65
|
-
const requestsRemaining = MAX_WINDOW_REQUEST_COUNT - totalWindowRequestsCount;
|
66
|
-
const msg = `Requests made by client: ${totalWindowRequestsCount}\nRequests remaining: ${requestsRemaining}`;
|
67
|
-
logger.log('info', msg);
|
68
|
-
}
|
69
|
-
// if number of requests made is greater than or equal to the desired maximum, return error
|
70
|
-
if (totalWindowRequestsCount >= MAX_WINDOW_REQUEST_COUNT) {
|
71
|
-
return await closeConnection({ code: ERROR_CODE });
|
72
|
-
}
|
73
|
-
// if number of requests made is less than allowed maximum, log new entry
|
74
|
-
const lastRequestLog = data[data.length - 1];
|
75
|
-
const potentialCurrentWindowIntervalStartTimeStamp = currentRequestTime
|
76
|
-
.subtract(WINDOW_LOG_INTERVAL_IN_MINUTES, 'minutes')
|
77
|
-
.unix();
|
78
|
-
// if interval has not passed since last request log, increment counter
|
79
|
-
if (lastRequestLog[timestampName] > potentialCurrentWindowIntervalStartTimeStamp) {
|
80
|
-
lastRequestLog[countName]++;
|
81
|
-
data[data.length - 1] = lastRequestLog;
|
82
|
-
} else {
|
83
|
-
// if interval has passed, log new entry for current user and timestamp
|
84
|
-
data.push({
|
85
|
-
[timestampName]: currentRequestTime.unix(),
|
86
|
-
[countName]: 1
|
87
|
-
});
|
88
|
-
}
|
89
|
-
await redisClient.set(req.ip, JSON.stringify(data));
|
90
|
-
return await closeConnection();
|
91
|
-
});
|
92
|
-
} catch (err) {
|
93
|
-
return await closeConnection(err);
|
94
|
-
}
|
95
|
-
};
|
96
|
-
};
|
@@ -1,15 +0,0 @@
|
|
1
|
-
<title>{{#t}}pages.confirmation.title{{/t}} – GOV.UK</title>
|
2
|
-
|
3
|
-
{{<partials-page}}
|
4
|
-
{{$page-content}}
|
5
|
-
<div class="alert-complete" role="alert">
|
6
|
-
<span class="icon icon-complete" role="presentation"></span>
|
7
|
-
<div class="alert-message">
|
8
|
-
<h1>{{#t}}pages.confirmation.alert{{/t}}</h1>
|
9
|
-
</div>
|
10
|
-
</div>
|
11
|
-
<h2>{{#t}}pages.confirmation.subheader{{/t}}</h2>
|
12
|
-
<p>{{#t}}pages.confirmation.content{{/t}}</p>
|
13
|
-
<a href="/landing-page" class="button" role="button">{{#t}}buttons.start-again{{/t}}</a>
|
14
|
-
{{/page-content}}
|
15
|
-
{{/partials-page}}
|