Commit Graph

18 Commits

Author SHA1 Message Date
Anders Kaseorg 663f1a387d puppeteer_lib: Explode CommonUtils class.
This may have originally made sense as a class that managed the
browser state, but it has since turned into a dumping ground for
mostly pure functions that don’t make sense to instantiate.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-09-11 12:53:20 -07:00
Ganesh Pawar 10a0bf4de4
settings: Add confirmation dialog to delete linkifiers.
Fixes part of #22812.
2022-09-07 11:29:18 -07:00
Ganesh Pawar 1e8bfa710e dialog_widget: Migrate modal to Micromodal.
Also removed the `danger_submit_button` config option
from the dialog_widget since it isn't needed in the new modals.
2021-10-26 18:20:17 -07:00
Alex Vandiver 8dd9b4e812 linkifiers: Loosen regex that validates URLs.
User-supplied custom realm filter has had some sort of regex-based
validation of the format URL since their introduction in
d7e1e4a2c0 -- and this has always been
in addition to the URLValidator.  The URLValidator is the one which
does the security-relevant work of validating that the schema is
reasonable, and that the overall shape of the URL is well-formed.  The
regex has served primarily to arbitrary limit the characters that can
appear in the URL, in the mistaken name of safety.

Adjust the regex, such that its only purpose is to verify that the
usages of `%` characters in the URL are reasonable, and leave the URL
validation to the URLValidator, which can do a far better job.  This
includes broadening the support to include `%%` as an escape
character; this is likely such a niche case as to be unnecessary, but
costs little.

Fixes #16013.
2021-10-22 13:00:20 -07:00
Alex Vandiver db934be064 CVE-2021-41115: Use re2 for user-supplied linkifier patterns.
Zulip attempts to validate that the regular expressions that admins
enter for linkifiers are well-formatted, and only contain a specific
subset of regex grammar.  The process of checking these
properties (via a regex!) can cause denial-of-service via
backtracking.

Furthermore, this validation itself does not prevent the creation of
linkifiers which themselves cause denial-of-service when they are
executed.  As the validator accepts literally anything inside of a
`(?P<word>...)` block, any quadratic backtracking expression can be
hidden therein.

Switch user-provided linkifier patterns to be matched in the Markdown
processor by the `re2` library, which is guaranteed constant-time.
This somewhat limits the possible features of the regular
expression (notably, look-head and -behind, and back-references);
however, these features had never been advertised as working in the
context of linkifiers.

A migration removes any existing linkifiers which would not function
under re2, after printing them for posterity during the upgrade; they
are unlikely to be common, and are impossible to fix automatically.

The denial-of-service in the linkifier validator was discovered by
@erik-krogh and @yoff, as GHSL-2021-118.
2021-10-04 21:26:24 +00:00
sahil839 e0ab9e52b5 settings: Use dialog_widget for edit-linkifier modal.
This commit changes the edit-linkifier modal to use
dialog_widget instead of edit_fields_modal.
The edit_fields_modal module will be removed in
further commits to avoid code duplication.
2021-07-14 13:02:26 -07:00
Tim Abbott a8ac48082f puppeteer: Fix reference to #edit-linkifier-status.
This fixes a CI failure, likely introduced when rebasing
b04647f219.
2021-06-24 17:35:25 -07:00
sahil839 b04647f219 settings: Use edit_fields_modal framework for linkifier-edit modal.
This commit modifies the linkifier-edit modal to use newly added
edit_fields_modal framework.

One important change is that we remove the "edit-linkifier-status"
element as the corresponding "edit-fields-modal-status" element
is added in edit_fields_modal.hbs and we also modify the css
accordingly. This "edit-fields-modal-status" is used only for
this modal and remains empty for others, so this change does not
cause problems with other modals.

There is another element which uses "edit-linkifier-status" as a
class, but the css we defined was for "edit-linkifier-status" as
id, so the css change is also safe.
2021-06-24 16:55:23 -07:00
Rohitt Vashishtha 98f8d94b25 linkifiers: Add joint validation for linkifier urls and patterns.
We now validate the linkifier urls and patterns together, and add
the following additional checks:

1. All groups in the pattern must be used in the URL format string.
2. All groups in the URL format string must be declared in the pattern.

Linkifier pattern is now validated inside the `clean` method.
`filter_pattern_validator` is moved from `clean_fields` to `clean`
method as a safe check. As a result of this, a Puppeteer test case
is updated.

NOTE: The changes here are IN ADDITION to the existing validations.

Fixes #16482.

Co-authored-by: akshatdalton <akshat.dak@students.iiit.ac.in>
2021-06-16 17:51:33 -07:00
Riken Shah 7ae5e7287b puppeteer_test: Add `wait_for_modal_to_close` method to `CommonUtils`.
This commit adds the `wait_for_modal_to_close` method
and replaces all the instances where we are using jQuery
to check if the modal is closed.
2021-06-03 09:23:54 -07:00
Riken Shah fe30cfe680 puppeteer: Add `realm-linkifier.ts` test after fixing all the flakes.
9126ed33c9 commit removed this test as it
was very flaky.
2021-06-02 15:47:34 -07:00
Tim Abbott 9126ed33c9 puppeteer: Remove failing linkifier tests.
I'm not sure that settings UI is particularly worth having puppeteer
tests for, so it's possible we shouldn't bring these back at all.  But
in any case, it's worth disabling them as they've been failing for
some time.
2021-05-18 19:16:47 -07:00
Riken Shah e4bbfe5eb7 puppeteer_test: Add wait call for linkifier table to get updated.
This commit solves a rare flake, where the `realm
_linkifier.ts` test was failing because there was no
appropriate wait call for the table
(`#admin_linkifiers_table`) to get updated after editing
the pattern.
2021-05-18 18:46:17 -07:00
Riken Shah 2015d55a17 puppeteer_test: Use edit linkifier modal's id to check if it's closed. 2021-05-18 18:46:17 -07:00
akshatdalton 7632541afb edit_linkifier: Remove unnecessary error message display.
We want the error message that we get on editing the
linkifier to be displayed only on the edit linkifier modal.
2021-05-12 20:32:35 -07:00
akshatdalton 43aee21dcc linkifiers: Add frontend support to edit linkifier.
A modal is added to edit the realm linkifier which
supports ui_report error.

Puppeteer tests to verify linkifier update and an
invalid test to verify that linkifier error messages
are reported on the modal are added as well.
2021-05-09 20:12:25 -07:00
Abhijeet Prasad Bodas f896a7667f refactor: Update some uses of "filter" to "linkifier".
This updates some comments and local variables
which could be changed without breaking other
stuff.
2021-04-05 18:14:07 -07:00
Riken Shah f6998d6fee puppeteer_tests: Remove sequential numbers from test files.
The only downside of this is that it makes it harder to control the
order of these tests; which isn't that important.  And the structure
of naming each with its test order fundamentally requires renaming
files when adding/deleting tests, so if we want to control the default
test order, we'd be better off doing that by just hardcoding a list in
the test runner code.
2021-04-01 07:46:13 -07:00