Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing CSRF protection #111

Closed
ghost opened this issue Jul 19, 2017 · 9 comments
Closed

Missing CSRF protection #111

ghost opened this issue Jul 19, 2017 · 9 comments
Assignees
Milestone

Comments

@ghost
Copy link

ghost commented Jul 19, 2017

php/save.php and php/controller.php can be called without authentication cookie or CSRF token.

@ghost ghost added bug security labels Jul 19, 2017
@ghost ghost added this to the Release 1.0 milestone Jul 19, 2017
@ghost ghost added the backend label Aug 10, 2017
@ghost ghost modified the milestones: Release 1.0, Release 1.1 Apr 23, 2018
ghost pushed a commit that referenced this issue Sep 25, 2018
1.0.2 Bugfix release

 ### Backend
- Emit a more specific error message for cases like #160.
- The timeout for calls to `intelmqctl` has been raised to 20s (#164).

 ### Pages

 #### Configuration
- Underscore is now allowed for new parameter names (#153).

 #### Monitor
* Fix link to monitor page (#157).

 ### Documentation
- Add a FAQ and add a section about the docker issue (#160).
- Add instructions for Debian 9, Ubuntu 18.04, and openSUSE Leap 42.3, 15.0 (#168).

 ### Packaging
- Include a positions file matching the default configuration of intelmq (#171).

 ### Known issues
* Missing CSRF protection (#111).
* Missing copyright notices (#140).
* Graph jumps around on "Add edge" bug component (#148).
* new runtime parameters with _ not possible (#153).
* wrong error message for new bots with existing ID (#152).
* Queue size for deleted queue remains displayed (#158).
@ghost ghost modified the milestones: 1.1.0, 1.1.1 Nov 12, 2018
@ghost ghost modified the milestones: 1.1.1, 2.0.1 May 22, 2019
@ghost ghost modified the milestones: 2.0.1, 2.1.1 Feb 18, 2020
@bernhardreiter
Copy link
Contributor

bernhardreiter commented Mar 4, 2020

Looking at the issue to see if customers are interested.

Seems https://api.jquery.com/jQuery.getJSON/ calls are used in the php files,
we would need to modify them to add custom headers (which is one way for CSRF protection),
the other would be secure and samesite cookies.

So .getJSON to .ajax() and considering if using a different jquery or other library (as bundled jquery 1.11 is getting old).

@bernhardreiter
Copy link
Contributor

bernhardreiter commented Mar 4, 2020

Things which need to be done (aka rough plan):

  • add javascript/html dialog to enter credentials and show successful or unsuccessful log-in
  • add a backend endpoint to verify credentials (also way to save and manage credential infos on the backend)
  • make security token be saved in the javascript part (e.g. in sessionStorage)
  • evaluation if to use safe cookie or just a xhttp request header or both for enough protection
  • change backend to accept security tokens
  • replace .getJSON calls with .ajax() or different library to add a header (or cookie or both).
  • (optional) check important js libraries for needed updated (e.g. jquery 1.11 -> jquery 1.12.4 or 3.x or a different library altogether)

@bernhardreiter
Copy link
Contributor

Sunet contracted us (from Intevation) do resolve this issue, timeframe is within two month.

@bernhardreiter
Copy link
Contributor

bernhardreiter commented Jun 9, 2020

We need longer to fix this. (Corona has slowed us down, among other things.)
Our plan is to make progress this months, and get it done before the summer holidays at least. #142 maybe a blocker and not optional, as it does not make sense to add hacks to the old jquery version.

@bernhardreiter
Copy link
Contributor

#142 seems to be under control, our new branch https://github.com/Intevation/intelmq-manager/tree/dev-python-backend-webpart has updated jquery and bootstrap libraries.

web client part

Now it would be useful to have a modal bootstrap3 login form from the webapp which works by using a POST endpoint and gets a token that will be used in subsequent requests to the server as part of the header. To have a backend to develop against, it would be cool to have a hug example, see hugapi/hug#863

We also have to make sure that the token is saved on the client, even if the page is switched, maybe the localsession storage can be used for this.

@ghost ghost modified the milestones: 2.1.2, 2.3.0 Jun 23, 2020
CSIRT-CZ pushed a commit to CZ-NIC/intelmq-manager that referenced this issue Jun 24, 2020
2.2.0 Feature release

This IntelMQ Manager version requires IntelMQ >= 2.2.0.

 ### Backend
- `config`: Get file paths from `intelmctl debug --get-paths` if possible and fall back to hard-coded paths otherwise. Thereby environment variables influencing the paths are respected (certtools#193).

 ### Pages
 #### About
- Show output of `intelmqctl debug`.

 ### Documentation
- Update release from intelmq's release documentation.
- Update Installation documentation: Fix & update dependencies and supported operating systems.

 ### Packaging
- Update default `positions.conf` to the default runtime/pipeline configuration of intelmq >= 2.1.1.

 ### Known issues
* Missing CSRF protection (certtools#111).
* Graph jumps around on "Add edge" (certtools#148).
* wrong error message for new bots with existing ID (certtools#152).
* `ALLOWED_PATH=` violates CSP (certtools#183).
* Monitor page: Automatic log refresh reset log page to first one (certtools#190).
@bernhardreiter
Copy link
Contributor

Some progress on our side in small steps:

  • on client side, https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage works over our page switches in the Manager
  • on server side we need a persistent storage of session data, which should work with several processes from python. We've started with sqlite (which is close to postgresql) in https://github.com/Intevation/intelmq-manager/tree/wip-csrf an alternative would be redis or a different message queue (abused) as db that IntelMQ uses anyway, however we should stay indepentend with the Manager for now.
  • for fast token verification on the backend side there are two approaches
    a) always access the (shared) db
    b) use cryptography, e.g. https://pypi.org/project/jwt/
    As we need a user database anyway we'll first try to see if we can make sqlite access fast via each python thread having one connection

@bernhardreiter
Copy link
Contributor

bernhardreiter commented Jul 7, 2020

technical how to connect fast to a persistent session and user db

Idea: Using sqlite with a small db file should leave this file in the memory via the file system caches.

One problem: the sqlite3 module is not threadsafe and apache and other web server may use threads to requests fast.

Solution-idea: Trying a different python module apsw which is thread-safe (https://rogerbinns.github.io/apsw/pysqlite.html#pysqlitediffs)

Turns out apsw has problems with mod_wsgi (at least in our tests it did not work well, we expect the use of python subinterpreters and forking by mod_wsgi as possible root for conflicts between the two pieces of software.) So we went back to pysqlite.

@bernhardreiter
Copy link
Contributor

#202 implements a working version of CSRF protection (with some rough edges, but it is a significant improvement over having no protection).

@ghost
Copy link
Author

ghost commented Oct 21, 2020

I think we can close here, as the authentication part is done. Thanks @Intevation for the implementation and @SUNET for the funding!

@ghost ghost closed this as completed Oct 21, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant