Commit Graph

38 Commits

Author SHA1 Message Date
Leo Hemsted
5bbbdc3cd9 fix xss with service letter contact blocks
service contact blocks contain new lines - and jinja2 normally ignores
newlines (as in it keeps them as new lines) - but we need to turn them
into `<br>` tags so that we can show the formatting that the user has
added. We were previously just doing `{{ block | nl2br | safe }}`. nl2br
turns the new lines into `<br>` tags, and then `safe` tells jinja that
it doesn't need to escape the html.

this causes issues if the user adds `<script>alert(1)</script>` to their
contact block (or some other evil xss hack), where that will get let
through due to the safe flag

To solve this, use `Markup(html='escape')` to sanitise any html, and
then convert new lines to <br>.

bump utils

another xss
2020-01-21 17:34:49 +00:00
Pea Tyczynska
21e6d994b9 Validate service and organisation name 2019-11-20 13:31:01 +00:00
Rebecca Law
18e3eb6b32 Update tests for content changes. 2019-09-23 13:22:28 +01:00
karlchillmaid
4b2990e735 Replace isn't with is not 2019-09-23 13:22:00 +01:00
karlchillmaid
653c2c399f Replace won't with will not 2019-09-23 13:21:59 +01:00
Katie Smith
5be6b41195 Allow Welsh characters in SMS
- This brings in the latest version of notifications-utils which
allows Welsh characters in SMS templates.
- Updated the pricing page to show the new prices for SMS with certain
Welsh characters
2019-05-15 14:20:49 +01:00
Chris Hill-Scott
470b8a2912 Remove domains from branding forms
We’re deprecating storing the domain as text on a branding in favour of
a database relationship between branding and organisation.

We need to do this now in order to remove the validation on these fields
(which depends on the data in `domains.yml`)
2019-04-12 15:23:07 +01:00
Chris Hill-Scott
184a9fa605 Use email fields for feedback form
Otherwise we can end up collecting invalid email addresses…

This required some refactoring to allow our email fields to be optional
(but not by default).
2018-12-07 13:11:41 +00:00
Chris Hill-Scott
34ed0da362 Validate non canonical domains
At the moment we transform what the user gives us, so if someone enters
`digital.cabinet-office.gov.uk` it will automagically be saved as
`cabinet-office.gov.uk`. This happens without the user knowing, and
might have unintended consequences.

So let’s tell them what the problem is, and let them decide what to do
about it (which might be accepting the canonical domain, or adding a
new organisation to domains.yml first).
2018-09-06 12:35:52 +01:00
Chris Hill-Scott
80423dfb3f Don’t allow adding unknown domains to branding lookup
We should make sure we’re not putting typos in the branding list. We can
validate what gets entered here against our known list of public-sector
domains.
2018-09-05 10:32:43 +01:00
Katie Smith
58cc1604a7 Bump utils and sanitise header values
Updated notifications-utils. This brings in
- the renamed character sanitization classes
- the change to allow unicode in letter addresses (this lets us delete
a test that is no longer relevant)

Also replaced non-ascii characters in headers. This fixes a bug where
non-ascii characters in a CSV filename were causing errors since the
filename is also used in the header.
2018-05-25 10:34:47 +01:00
Katie Smith
11a6c8cfb5 Update SMS sender validation to reject senders starting with 00
Having SMS senders that start with 00 can cause issues with Firetext due
to Firetext's validation rules, so we shouldn't allow SMS senders to start
with 00.

Firetext treats a double 00 at the start of the senderID as an international
prefix, so removes them. A sender of 00447876574016 would become 447876574016.

Under Firetext's validation rules, an SMS sender of five 0s (00000) would
become  4400. This is because the first 00 are removed (as the international
prefix). The third 0 is seen as the start of a phone number, and becomes 44,
leaving the final 00 = 4400.
2018-02-28 13:40:20 +00:00
Chris Hill-Scott
f3a0c505bd Enforce order and style of imports
Done using isort[1], with the following command:
```
isort -rc ./app ./tests
```

Adds linting to the `run_tests.sh` script to stop badly-sorted imports
getting re-introduced.

Chosen style is ‘Vertical Hanging Indent’ with trailing commas, because
I think it gives the cleanest diffs, eg:
```
from third_party import (
    lib1,
    lib2,
    lib3,
    lib4,
)
```

1. https://pypi.python.org/pypi/isort
2018-02-27 16:35:13 +00:00
Leo Hemsted
31a4cc15c9 validate email addresses in one-off flow
previously we were just using the wtforms builtin email validator,
which is much more relaxed than our own one. It'd catch bad emails when
POSTing to the API, resulting in an ugly error message. It's easy work
to make sure we validate email addresses as soon as they're entered.
2018-02-14 14:35:16 +00:00
Chris Hill-Scott
934a271322 Allow full stops in SMS senders
We have a team who want their (short) web address as the text message
sender. This commit updates the validation of text message senders to
allow `.` as a valid character, which is currently blocking them from
doing this.

We can be fairly confident this works because:

- the team are sending large volumes of messages already with their
  existing provider
- we’ve tested it with all combinations of
  - both our text message providers
  - an Android phone and n iPhone
2018-01-31 11:11:44 +00:00
Chris Hill-Scott
b11653fe08 Refactor to use validator class
Using a separate validator class to check for appropriate characters in
a text message sender means that we’re not doing this validation in a
different way from the other checks (length and required). So the code
is cleaner.
2018-01-31 11:11:32 +00:00
Chris Hill-Scott
eef66b70de Reword because ‘inbetween’ isn’t a word 2017-12-11 11:19:33 +00:00
Chris Hill-Scott
242a216c1b Update error message about commas in placeholders
We call the yellow things ‘double brackets’ on the frontend, not fields
or placeholders. This error message was a bit out of date.

Also refactored it to use the `Field` class; this code was probably
written before `Field` was factored out of `Template`.
2017-12-11 11:19:33 +00:00
Chris Hill-Scott
a10e76a9c2 Stop referring to central gov in error messages 2017-08-10 13:51:46 +01:00
Leo Hemsted
f550699daf fix non-gsm error message
Use `it`/`they` depending on how many different characters you've used
Also don't wrap the message with quotes, as it looks confusing and
potentialy implies that you can't use apostrophes
2017-02-17 10:39:52 +00:00
Leo Hemsted
73a965a3c6 allow downgradeable unicode characters in SMS templates 2017-02-17 10:39:52 +00:00
Leo Hemsted
41fa158635 error when users put non-GSM chars in a sms template
additionally, this moves the formatted_list jinja macro into a python
function, so that it can be called from the form validator
2017-02-17 10:39:52 +00:00
Chris Hill-Scott
1df3c11ae9 Split support into two pages
The kind of communications we’re getting at the moment can broadly be
broken down into:
- problems
- questions and feedback

We will need to triage problems differently, because they could
potentially be urgent/severe/emergency/P1/whatever language we use.
Questions or feedback will never be P1.

Two reasons for making the user categorise their tickets themselves:

- Outside of hours we can’t get someone out of bed in order to decide if
  a ticket is a problem or just feedback

- We can tailor the subsequent pages to whether it’s a problem or
  feedback (eg showing a link to the status page if the user is having
  a problem)

This commit let’s users make the choice with a pair of radio buttons.

It also cleans up a bunch of the tests and parameterizes them so we’re
testing the flow for both ticket types.
2017-02-02 15:18:40 +00:00
Imdad Ahad
5ecdbb8596 Refactor to use a cleaner and lean regex 2016-10-28 10:45:05 +01:00
Chris Hill-Scott
136662bd30 Stop people using very common passwords
If a user chooses a very common password then an attacker could guess it
in relatively few attempts, circumventing the lockout.

CESG recommend blacklisting the most common passwords:

> …enforcing the requirement for complex character sets in passwords is
> not recommended. Instead, concentrate efforts on technical controls,
> especially:
>
> - defending against automated guessing attacks by either using account
>   lockout, throttling, or protective monitoring
> - blacklisting the most common password choices

How I made this list:

- went to the OWASP repository of security lists:
  https://github.com/danielmiessler/SecLists

- downloaded `10k_most_common.txt`, `twitter-banned.txt` and
  `500-worst-passwords.txt`

- filtered out any under 8 characters:
  ```
  sed -r '/^.{,7}$/d' passwords-twitter.txt > passwords-combined.txt
  sed -r '/^.{,7}$/d' passwords-500.txt >> passwords-combined.txt
  sed -r '/^.{,7}$/d' passwords.txt >> passwords-combined.txt
  ```

- filtered out any duplicates:
  ```
  cat passwords-combined.txt | awk '!x[$0]++' > passwords-combined-deduped.txt
  ```
2016-09-27 11:51:12 +01:00
Chris Hill-Scott
1409ca36ca Accept common spreadsheet formats, not just CSV
We require users to export their spreadsheets as CSV files before
uploading them. But this seems like the sort of thing a computer should
be able to do.

So this commit adds a wrapper class which:
- takes a the uploaded file
- returns it in a normalised format, or reads it using pyexcel[1]
- gives the data back in CSV format

This allows us to accept `.csv`, `.xlsx`, `.xls` (97 and 95), `.ods`,
`.xlsm` and `.tsv` files. We can upload the resultant CSV just like
normal, and process it for errors as before.

Testing
---

To test this I’ve added a selection of common spreadsheet files as test
data. They all contain the same data, so the tests look to see that the
resultant CSV output is the same for each.

UI changes
---

This commit doesn’t change the UI, apart from to give a different error
message if a user uploads a file type that we still don’t understand.

I intend to do this as a separate pull request, in order to fulfil
https://www.pivotaltracker.com/story/show/119371637
2016-05-15 22:10:58 +01:00
Nicholas Staples
f581ff44d0 Only check on csv is the file extension.
Update validator logic

Update message for the validator.
2016-05-03 10:10:58 +01:00
Pete Herlihy
636facb71c Updated the contact us link for non gov.uk domains trying to register. 2016-04-25 10:18:33 +01:00
Rebecca Law
2afbbd6423 Removed unused requirements and modules. 2016-04-21 09:11:00 +01:00
Nicholas Staples
3865c722fc Updated notifications_utils version and associated code. Added email subject formatting for placeholders. 2016-04-14 12:00:55 +01:00
Chris Hill-Scott
dfd8540b54 Don’t allow commas in placeholders
> If a user tries to save a template containing something like
> ((name,date)) we should give a validation error.

This is because it causes havoc with the column headers in CSV files.

https://www.pivotaltracker.com/story/show/117043389
2016-04-08 07:46:14 +01:00
Nicholas Staples
2352b0f80d Fix issue with uppercase in the domain name. 2016-04-06 16:45:35 +01:00
Nicholas Staples
f0b604084c Fixed email bug and added new exhaustive tests. 2016-04-06 11:01:37 +01:00
Nicholas Staples
8a203c0155 Valid email domains added and tests passing. 2016-03-18 12:05:50 +00:00
Nicholas Staples
6959d695d3 Working tests, hopefully all code changes done. 2016-01-27 12:22:32 +00:00
Adam Shimali
584533eb11 First slice of csv upload of phone numbers for sending messages.
At the moment the file contents are not persisted by checked in
memory.

The first and last three records are show if all are valid.

If there are invalid rows, they are reported and the user is
prompted to go back and sort out upload file.

The storing of upload result (i.e. validation of file) in session
will be removed in next story which is about persisting of file
for later processing.
2016-01-11 15:00:51 +00:00
Nicholas Staples
7001d8261d Fix for security hole with setting session['user_id'] before second factor of authentication has been authorised. 2016-01-07 12:43:10 +00:00
Rebecca Law
3b96b6e5ca 108536374: Implement a validator to exclude passwords on a blacklist 2015-12-01 16:45:11 +00:00