Commit Graph

588 Commits

Author SHA1 Message Date
Jason Phan ab9d3a86de Clean up cls checks in Validation::optional() 2021-01-02 10:49:30 -05:00
Jason Phan 06cfef275a Remove allow_none parameter from Validation::optional()
The parameter isn't used by any sr.ht service and is functionally
redundant as there is Validation::required().

The if block which sets default values is also fixed. Prior to this
commit, it would only set default values for keys that did not exist in
the incoming request. For things like logging in, this was incorrect
behavior.
2021-01-02 10:49:29 -05:00
Jason Phan 2c2044044f Properly check empty/missing optional form parameters
Some request forms contain keys with empty values. For instance, logging
in from https://meta.sr.ht will generate a request containing the
"return_to" key with a value of "". Similarly, registering without
providing a PGP key generates a request containing the "pgp-key" key
with a value of "".

In such cases, calls to Validation::optional() do not behave as
expected. Since "" != None, the first two top-level if blocks are
immediately skipped in Validation::optional(), even though the second
block is where any default values are set.

In the case of logging in, this results in users being redirected to ""
instead of the specified "/".  Luckily, redirecting to "" is apparently
the same as redirecting to "/", so nothing catastrophic happens.
However, this clearly is an unintended side-effect, and not desired
behavior.
2021-01-02 10:49:29 -05:00
Jason Phan e1e54174ec Make werkzeug.wsgi middleware imports the fallback option
This change swaps the attempted import order around so that the
newer imports are tried first.
2020-12-27 11:15:59 -05:00
Jason Phan cb60540946 debug: Fix old SharedDataMiddleware import
In werkzeug 1.0, SharedDataMiddleware lives at
werkzeug.middleware.shared_data, not werkzeug.wsgi.
2020-12-27 10:44:55 -05:00
Drew DeVault 77d2a8875c Many tweaks & improvements to the dark theme 2020-12-16 10:05:04 -05:00
Robert Hencke 528e4a335e Add alembic to package dependencies 2020-12-15 15:54:40 -05:00
Alexey Yerin fda5790de5 Don't color buttons in alerts in dark theme
Signed-off-by: Alexey Yerin <yerinalexey98fd@gmail.com>
2020-12-15 15:53:39 -05:00
Alexey Yerin b0a261c9fd Fix color for :focus-ed links in dark mode
Signed-off-by: Alexey Yerin <yerinalexey98fd@gmail.com>
2020-12-15 15:34:49 -05:00
Drew DeVault 8c8ca9d9c7 Add dark theme support code 2020-12-15 13:59:26 -05:00
Nolan Prescott 9a95abb66b Allow id attribute on sanitized anchor tags
Previously the sanitizer attributes dictionary was created by updating
the desired whitelist with `bleach.sanitizer.ALLOWED_ATTRIBUTES` which
is (at the time of this writing):

    {'a': ['href', 'title'], 'abbr': ['title'], 'acronym': ['title']}

By updating the whitelist dictionary with a duplicated key (`a`), the
whitelist value is overwritten.

Instead, build a new dictionary by merging the two dictionaries with a
preference for the whitelisted values. To accommodate the overwrite
behavior the whitelist is expanded to include those default values.
2020-12-10 08:51:04 -05:00
TRS-80 fe16d27090 Add id to list of permitted anchor attributes 2020-12-06 09:37:51 -05:00
Drew DeVault 403b26c508 Work around pygments GraphQL issue 2020-11-21 13:00:19 -05:00
Alva 8bedd6a2da Allow gemini and gopher URIs on profile 2020-11-08 10:40:22 -05:00
Remco van 't Veer 028eea95f5 pagination: escape search keys
Fix for paging through, for instance, hashtag searches.
2020-10-31 10:53:44 -04:00
Thorben Günther 161538720a Redirect users to hub instead of their meta profile 2020-10-31 10:47:55 -04:00
Drew DeVault c79a926b96 Don't abort startup if we can't reach meta 2020-10-28 06:25:25 -04:00
Drew DeVault d6c758f8d4 lookup_user: return none on 404 from meta.sr.ht 2020-10-14 12:03:20 -04:00
Drew DeVault 6bab96abf9 Internal auth: fix invalid auth for profile req
The AbstractOAuthService.lookup_user function is used to fetch users
either from the local database or from meta.sr.ht, and the
implementation creates an Internal auth token for the requested
username. If that user does not exist, this previously tripped an
assertion failure in this code. This case now raises a 404 error, and
the assertion is made more specific.
2020-10-09 11:07:15 -04:00
Drew DeVault e67e4d17f8 crypto: add TTL to internal auth tokens
30 seconds to match the TTL used by core-go
2020-10-09 11:01:11 -04:00
Drew DeVault cbce9a4e00 layout.html: add pagination links 2020-10-08 18:20:11 -04:00
gildarts df403d6717 Fix alignment and sizing of header anchor tags
- Switch to `inherit` for font-size to allow the achor to change as the
  font-size of the anchor changes
- Switch to relative spacing so that the position change also adjusts
  with header text size.
- Remove margin rule that appeared to be causing issues aligning the
  header properly.
2020-10-02 14:25:27 -04:00
наб e9ee60a1b0 Space out images in markdown headings
Implementation by ~gildarts, as seen on sr.ht-discuss@:
<1b6adf60-5a15-4467-c358-4a75deee0e38@orbital.rocks>,
consult that thread for rationale
2020-09-28 17:09:50 -04:00
Drew DeVault 33182c88c9 encrypt_request_authorization: add client support 2020-09-24 15:34:49 -04:00
Vasilij Schneidermann c6f30c97d1 Align header items on baseline with margin 2020-09-24 15:34:40 -04:00
Ignas Kiela 6386f1c2d8 Remove anchor link animation depending on prefers-reduced-mortion media query 2020-09-15 13:38:07 -04:00
Drew DeVault 461fcdc002 Correct oversight in previous patch 2020-09-15 12:20:05 -04:00
gildarts d67a56a31d Remove extra # from toc generation
Sorry for the confusion on my end with the previous patches.
2020-09-15 12:12:22 -04:00
gildarts 22dca28205 Add aria-hidden param to anchor tag 2020-09-15 10:59:17 -04:00
Drew DeVault 8df2c7d577 Improve logging on missing client assertion 2020-09-14 22:32:09 -04:00
Drew DeVault 031fe52af8 Fix issues with internal auth for new users 2020-09-14 20:30:01 -04:00
gildarts 6003ccc812 Add bare anchor tag for header link 2020-09-14 11:55:46 -04:00
Drew DeVault 555e10eee2 Set internal auth client name to app.site 2020-09-12 15:03:10 -04:00
наб 0e356681f8 search: add term_map to transform terms before parsing
Also the god-forsaken deafult typo, since I'm here already and it's
not a kwarg
2020-09-11 10:14:04 -04:00
Drew DeVault c89c1e0392 Limit select styles to affect single-select only 2020-09-09 10:00:56 -04:00
Drew DeVault ef89ff1a0a srht.email: generalize exception email support 2020-08-31 10:07:28 -04:00
наб 63753432c2 Include current user in 500 e-mails
Ref: ~sircmpwn/sr.ht#111
2020-08-26 09:49:48 -04:00
наб d3bb61dbeb Extract HTML sanitisation 2020-08-25 15:56:59 -04:00
Bor Grošelj Simić 069b737a23 Allow 1 as default value 2020-08-24 10:55:39 -04:00
Drew DeVault 4ac71aa83b srht/validation: check that JSON is a dict
Validation is based on dictionaries, and all requests which use
Validation are expecting a dict.
2020-08-24 10:35:21 -04:00
Drew DeVault 2005f4e578 coalesce_search_terms: correct operator precedence 2020-08-24 10:14:46 -04:00
наб 3ab8bdadb6 Also preserve sort across pages
Ref: ~sircmpwn/hub.sr.ht#39
2020-08-24 10:04:30 -04:00
наб b6a83d7ac7 Correctly bubble HTTP status in OAuthError
Before:
-- >8 --
nabijaczleweli@tarta:~$ curl -D/dev/stdout -H "Authorization: Bearer invalid-token" http://127.0.0.1:5001/api/repos/cabal/refs; echo
HTTP/1.1 200 OK
Server: gunicorn/19.9.0
Date: Mon, 17 Aug 2020 11:57:46 GMT
Connection: close
Content-Type: application/json
Content-Length: 58

{"errors": [{"reason": "Invalid or expired OAuth token"}]}
-- >8 --

After:
-- >8 --
nabijaczleweli@tarta:~$ curl -D/dev/stdout -H "Authorization: Bearer invalid-token" http://127.0.0.1:5001/api/repos/cabal/refs; echo
HTTP/1.1 400 BAD REQUEST
Server: gunicorn/19.9.0
Date: Mon, 17 Aug 2020 12:02:58 GMT
Connection: close
Content-Type: application/json
Content-Length: 58

{"errors": [{"reason": "Invalid or expired OAuth token"}]}
-- >8 --

Ref: ~sircmpwn/paste.sr.ht#18
2020-08-17 10:34:26 -04:00
Simon Ser a272a7532b Switch to SMTP.send_message
Let smtplib take care of the message formatting, because its encoding may
change depending on the capabilities of the SMTP server.
2020-07-27 13:30:46 -04:00
Simon Ser ea3758af11 Use smtp_from for MAIL FROM command in email.send_email
The smtp_user may not be a valid email address. If smtp_from is None,
smtplib will pick up the value of the From header automatically.
2020-07-27 13:30:45 -04:00
Simon Ser f152326d96 Never use unixfrom in email.send_email
The "From line" is only meant to be used in e-mail archives (eml or
mbox). SMTP expects a regular MIME message.
2020-07-27 13:30:45 -04:00
Peter Sanchez 331faa2aca Adding start_smtp helper function to email module 2020-07-22 14:00:53 -04:00
Drew DeVault c915363b78 Makefile: improve handling of static content 2020-07-17 08:41:39 -04:00
Drew DeVault 9268f32a61 markdown: add with_styles option 2020-07-13 15:59:24 -04:00
Drew DeVault 901ce3a2dc Update internal auth for forwards compat with gql 2020-07-13 13:17:02 -04:00