http://hg.code.sf.net:8000/p/roundup/code/atom-log/tip/roundup/cgi/exceptions.py Mercurial Repository: p/roundup/code: roundup/cgi/exceptions.py history 2025-08-11T14:01:12-04:00 [reauth-confirm_id] feat(security): Add user confirmation/reauth for sensitive changes http://hg.code.sf.net:8000/p/roundup/code/#changeset-ef1ea918b07a9a4febcb511cb4b18690324d81cd John Rouillard rouilj@ieee.org 2025-08-11T14:01:12-04:00 2025-08-11T14:01:12-04:00
changeset ef1ea918b07a
branch reauth-confirm_id
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description feat(security): Add user confirmation/reauth for sensitive changes

Auditors can raise Reauth(reason) exception to require the user to
enter a token (e.g. account password) to verify the user is performing
the change.

Naming is subject to change.

actions.py: New ReauthAction class handler and verifyPassword() method
for overriding if needed.

client.py: Handle Reauth exception by calling Client:reauth() method.
Default client:reauth method. Add 'reauth' action declaration.

exceptions.py: Define and document Reauth exception as a subclass of
RoundupCGIException.

templating.py: Define method utils.embed_form_fields().

The original form making a change to the database has a lot of form
fields. These need to be resubmitted to Roundup as part of the form
submission that verifies the user's password.

This method turns all non file form fields into type=hidden inputs.
It escapes the names and values to prevent XSS.

For file form fields, it base64 encodes the contents and puts them
in hidden pre blocks. The pre blocks have data attributes for the
filename, filetype and the original field name. (Note the original
field name is not used.)

This stops the file content data (maybe binary e.g. jpegs) from
breaking the html page. The reauth template runs JavaScript that
turns the encoded data inside the pre tags back into a file. Then
it adds a multiple file input control to the page and attaches all
the files to it. This file input is submitted with the rest of the
fields.

_generic.reauth.html (multiple tracker templates): Generates a form
with id=reauth_form to:

display any message from the Reauth exception to the user (e.g. why
user is asked to auth).

get the user's password

submit the form

embed all the form data that triggered the reauth

recreate any file data that was submitted as part of the form and
generate a new file input to push the data to the back end

It has the JavaScript routine (as an IIFE) that regenerates a file
input without user intervention.

All the TAL based tracker templates use the same form. There is also
one for the jinja2 template. The JavaScript for both is the same.

reference.txt: document embed_form_fields utility method.

upgrading.txt: initial upgrading docs.

TODO:

Finalize naming. I am leaning toward ConfirmID rather than Reauth.
Still looking for a standard name for this workflow.

Externalize the javascript in _generic.reauth.html to a seperate file
and use utils.readfile() to embed it or change the script to load it
from a @@file url.

Clean up upgrading.txt with just steps to implement and less feature
detail/internals.

Document internals/troubleshooting in reference.txt.

Add tests using live server.
files
refactor: move RateLimitExceeded to roundup.cgi.exceptions http://hg.code.sf.net:8000/p/roundup/code/#changeset-e882a5d52ae5e6900363d85ef206ec1b3f9b7676 John Rouillard rouilj@ieee.org 2025-08-10T21:27:06-04:00 2025-08-10T21:27:06-04:00
changeset e882a5d52ae5
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description refactor: move RateLimitExceeded to roundup.cgi.exceptions

RateLimitExceeded is an HTTP exception that raises code 429. Move it
to roundup.cgi.exceptions where all the other exceptions that result
in http status codes are located. Also make it inherit from
HTTPException since it is one.

Also add docstrings for all HTTP exceptions and order HTTPExceptions
by status code.

BREAKING CHANGE: if somebody is importing RateLimitExceeded they will
need to change their import. I consider it unlikely anybody is using
RateLimitExceeded. Detectors and extensions are unlikely to raise
RateLimitExceeded. So I am leaving it out of the upgrading doc. Just
doc in change log.
files
Doc: add docstrings to http exceptions http://hg.code.sf.net:8000/p/roundup/code/#changeset-700424ba015c2a0edea6b9e4635e2a0948d9f061 John Rouillard rouilj@ieee.org 2025-08-10T20:57:57-04:00 2025-08-10T20:57:57-04:00
changeset 700424ba015c
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Doc: add docstrings to http exceptions
files
flak8 spacing fixes. http://hg.code.sf.net:8000/p/roundup/code/#changeset-a1cffeef5f87965e6c0e99410c66dd96495b33f9 John Rouillard rouilj@ieee.org 2022-09-14T15:06:44-04:00 2022-09-14T15:06:44-04:00
changeset a1cffeef5f87
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description flak8 spacing fixes.
files
Summary: Add test cases for sqlite fts http://hg.code.sf.net:8000/p/roundup/code/#changeset-91ab3e0ffcd0d5550274ffda207241843ee6a545 John Rouillard rouilj@ieee.org 2022-01-23T18:57:45-05:00 2022-01-23T18:57:45-05:00
changeset 91ab3e0ffcd0
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Summary: Add test cases for sqlite fts

Add support for using the FTS5 full text query engine for sqlite.

Also stubbed out some sections for adding postgresql FTS support as
well.

Added nee indexer type native-fts. It is not selected by default. The
indexer=native is used if no indexer is set. This prevents an upgrade
from seeming to wipe out the native index if upgraded and
indexer=native is not explicitly set.

Docs updated. Also changed section headers to sentence case for the
current release notes.

Indexing backend can control if the full text search phrase is broken
into a list of words or passed intact. For backends with query
languages (sqlite and can be enabled for whoosh and xapian) we do not
want the phrase "tokenized" on whitespace.

This also updates the rdbms database version to version 7 to add FTS
table. I will be using the same version when I add postgresql. If
somebody runs this version on postgresql, they will have to manually
add the fts tables for postgresql if they want to use it.

Added a new renderError method to client. This allows errors to be
reported still using page.html rather than raw html. It also supports
templates for any error code. If no template for the error code
(e.g. 400) is found, the error in raw html with no page frame is
shown.

New IndexerQueryError exception to pass back message about query syntax
errors.
files
issue2551083 Replace BaseException and Exception with RoundupException http://hg.code.sf.net:8000/p/roundup/code/#changeset-c177e7128dc987e64d2a829d2dc81dc4538da17e John Rouillard rouilj@ieee.org 2020-04-03T16:18:59-04:00 2020-04-03T16:18:59-04:00
changeset c177e7128dc9
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description issue2551083 Replace BaseException and Exception with RoundupException

issue2551083 - Replace BaseException and Exception as base classes
with new RoundupException (inheriting from Exception) for most roundup
exceptions.
files
flake8 whitespace changes, suppress unused import warning http://hg.code.sf.net:8000/p/roundup/code/#changeset-0dc1e0222353d483ef35492105fb903139fc046e John Rouillard rouilj@ieee.org 2020-01-07T21:21:20-05:00 2020-01-07T21:21:20-05:00
changeset 0dc1e0222353
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description flake8 whitespace changes, suppress unused import warning
files
Make DetectorError print something in python2 http://hg.code.sf.net:8000/p/roundup/code/#changeset-08b241c9fea4e9a349bb80c6964da5c15dfcafb9 Ralf Schlatterbeck rsc@runtux.com 2019-09-09T19:39:08+02:00 2019-09-09T19:39:08+02:00
changeset 08b241c9fea4
branch
bookmark
tag
user Ralf Schlatterbeck <rsc@runtux.com>
description Make DetectorError print something in python2

Also works for python3, we call __init__ of the base class.
Hopefully fixes issue2551057.
files
Fix problem with cgi.escape being depricated a different way. This way http://hg.code.sf.net:8000/p/roundup/code/#changeset-883c9e90b4031a477a710c08c8686e18ba47fdbc John Rouillard rouilj@ieee.org 2019-07-06T13:12:58-04:00 2019-07-06T13:12:58-04:00
changeset 883c9e90b403
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Fix problem with cgi.escape being depricated a different way. This way
uses anypy and is cleaner. Also fixes incorrect/incomplete change that
resulted in escaped in TAL generated by TALInterpreter.py. The escaped
quotes break javascript etc. defined using tal string: values.

TODO: add test cases for TAL. This wouldn't have snuck through for a
month if we had good coverage of that library.
files
Call cgi.escape only on python 2. Replace with html.escapeif it can be http://hg.code.sf.net:8000/p/roundup/code/#changeset-1a835db4167402cc9a2fdf5eb4345b83b9e64607 John Rouillard rouilj@ieee.org 2019-06-11T21:29:24-04:00 2019-06-11T21:29:24-04:00
changeset 1a835db41674
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Call cgi.escape only on python 2. Replace with html.escapeif it can be
found.
files
Add etag support to rest interface to prevent multiple users from http://hg.code.sf.net:8000/p/roundup/code/#changeset-07abc8d36940fe0ac0ff0d0f605ed87f707851d4 John Rouillard rouilj@ieee.org 2019-03-01T22:57:07-05:00 2019-03-01T22:57:07-05:00
changeset 07abc8d36940
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Add etag support to rest interface to prevent multiple users from
overwriting other users changes.

All GET requests for an object (issue, user, keyword etc.) or a
property of an object (e.g the title of an issue) return the etag for
the object in the ETag header as well as the @etag field in the
returned object.

All requests that change existing objects (DELETE, PUT or PATCH)
require:

1 A request include an ETag header with the etag value retrieved
for the object.

2 A submits a form that includes the field @etag that must have
the value retrieved for the object.

If an etag is not supplied by one of these methods, or any supplied
etag does not match the etag calculated at the time the DELETE, PUT or
PATCH request is made, HTTP error 412 (Precondition Failed) is
returned and no change is made. At that time the client code should
retrieve the object again, reconcile the changes and can try to send a
new update.

The etag is the md5 hash of the representation (repr()) of the object
retrieved from the database.
files
Python 2 and 3 support. Convert Exception into BaseException in core code. http://hg.code.sf.net:8000/p/roundup/code/#changeset-32f95ec6bd8e058056dd9ab57d641a19f904281f John Rouillard rouilj@ieee.org 2017-09-04T21:56:49-04:00 2017-09-04T21:56:49-04:00
changeset 32f95ec6bd8e
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Python 2 and 3 support. Convert Exception into BaseException in core code.
files
issue2550826 IOError in detector causes apache 'premature end of script headers' error http://hg.code.sf.net:8000/p/roundup/code/#changeset-65fef7858606d6af4ad526186ba2c5235b1baa11 John Rouillard rouilj@ieee.org 2016-06-10T23:33:11-04:00 2016-06-10T23:33:11-04:00
changeset 65fef7858606
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description issue2550826 IOError in detector causes apache 'premature end of script headers' error

Capture all exceptions from auditors/reactors and raise a
DetectorError instead. This allows failures like IOErrors from the
detectors (e.g. unable to access files) to be handled. Previously an
IOError just resulted in no output (premature end of headers under
apache). Problem diagnosed and initial patch created by Tom Ekberg
(tekberg).

Patch application/mods and testing by rouilj.
files
XMLRPC improvements: http://hg.code.sf.net:8000/p/roundup/code/#changeset-bbab97f8ffb2f6e94262615a068f7878d9e572c0 Stefan Seefeld stefan@seefeld.name 2009-02-27T17:46:47+00:00 2009-02-27T17:46:47+00:00
changeset bbab97f8ffb2
branch
bookmark
tag
user Stefan Seefeld <stefan@seefeld.name>
description XMLRPC improvements:

* Add support for actions to XMLRPC interface.
* Provide bridge so user actions may be executed
either via CGI or XMLRPC.
* Adjust XMLRPC tests to recent work.
* Cleanup.
files
added LoginError; fix vim modeline http://hg.code.sf.net:8000/p/roundup/code/#changeset-df4a3355ee8fab9ba481e7bbbda4d55dbb3da70c Alexander Smishlajev a1s@users.sourceforge.net 2004-11-18T14:10:27+00:00 2004-11-18T14:10:27+00:00
changeset df4a3355ee8f
branch
bookmark
tag
user Alexander Smishlajev <a1s@users.sourceforge.net>
description added LoginError; fix vim modeline
files
in HTML produced by SeriousError.__str__(): http://hg.code.sf.net:8000/p/roundup/code/#changeset-93bd8c4d43efb6422e19b6a4a966f7591661ec08 Alexander Smishlajev a1s@users.sourceforge.net 2004-05-11T13:03:07+00:00 2004-05-11T13:03:07+00:00
changeset 93bd8c4d43ef
branch
bookmark
tag
user Alexander Smishlajev <a1s@users.sourceforge.net>
description in HTML produced by SeriousError.__str__():

remove misleading 'http-equiv' meta;
change stylesheet link from '_file/' to '@@file/'
for consistency with classic templates.
files
add and use Reject exception [SF#700265] http://hg.code.sf.net:8000/p/roundup/code/#changeset-3fd6722937126260b1675db4abfc06e34bc7ae1a Richard Jones richard@users.sourceforge.net 2004-03-26T00:44:11+00:00 2004-03-26T00:44:11+00:00
changeset 3fd672293712
branch
bookmark
tag
user Richard Jones <richard@users.sourceforge.net>
description add and use Reject exception [SF#700265]
files
cgi exceptions fix http://hg.code.sf.net:8000/p/roundup/code/#changeset-f6d7ccce8d9652409a152a97d7b3bc5269c77a92 Richard Jones richard@users.sourceforge.net 2004-02-29T01:16:20+00:00 2004-02-29T01:16:20+00:00
changeset f6d7ccce8d96
branch
bookmark
tag
user Richard Jones <richard@users.sourceforge.net>
description cgi exceptions fix
files
forward-port from maint branch http://hg.code.sf.net:8000/p/roundup/code/#changeset-78e6a1e4984ecae878ab841119a696cce8022eae Richard Jones richard@users.sourceforge.net 2004-02-25T23:27:54+00:00 2004-02-25T23:27:54+00:00
changeset 78e6a1e4984e
branch
bookmark
tag
user Richard Jones <richard@users.sourceforge.net>
description forward-port from maint branch
files
Move out parts of client.py to new modules: http://hg.code.sf.net:8000/p/roundup/code/#changeset-1782fe36e7b8c4988bb69c2b7098ec273888457c Johannes Gijsbers jlgijsbers@users.sourceforge.net 2004-02-11T21:34:31+00:00 2004-02-11T21:34:31+00:00
changeset 1782fe36e7b8
branch
bookmark
tag
user Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
description Move out parts of client.py to new modules:

* actions.py - the xxxAction and xxxPermission functions refactored
into Action classes

* exceptions.py - all exceptions

* form_parser.py - parsePropsFromForm & extractFormList in a FormParser class

Also added some new tests for the Actions.
files