Skip to content

Fix compatability, id cookies, and binding:file; add safety-limits [1.6] - #84

Merged
jeapostrophe merged 4 commits into
racket:masterfrom
LiberalArtist:wrap-up-1.6
Jan 14, 2020
Merged

jeapostrophe merged 4 commits into
racket:masterfrom
LiberalArtist:wrap-up-1.6

Conversation

@LiberalArtist

Copy link
Copy Markdown
Contributor

I'm still cleaning up various things in the safety-limits commit—most notably, I haven't adjusted the tests—and finishing another commit for the binding:file edge cases, but I thought I'd open a PR now to solicit comments. See #77 and #75 (comment) for earlier discussion.

As I proposed in #82 (comment), when we have consensus on the API changes, I plan to increment the web-server-lib version to 1.6 and open a corresponding PR in https://github.com/racket/typed-racket for typed/racket/http.

This commit changes the functions provided by `web-server/http/id-cookie`
to accept byte-strings for their name and value arguments (rather than
requiring strings) for consistency with other cookie-related functions:
see <RenaissanceBug/racket-cookies@c745ee5>.

Additionally, it fixes a bug which had caused cookie HMAC-SHA1 signatures
to be incorrectly truncated to 25 base64 digits, rather than 27,
since <racket@a5135d5>.

Other minor fixes:
- Corrects the documentatation for `valid-id-cookie?`
  and `request-id-cookie` to specify that the `#:timeout` argument
  must satisfy `real?` (not just `number?`).
- Changes the test suite for `make-secret-salt/file` to avoid needing write
  permissions for the directory where the collection is installed.

Closes racket#74
@LiberalArtist

LiberalArtist commented Dec 1, 2019 •

Copy link
Copy Markdown
Contributor Author

Here are some of the things that seem debatable:

Response timeouts: current-send-timeout vs. connection manager changes

The response-send-timeout is used in output-response and friends from web-server/http/response, which are used in a number of different call sites. I liked that #77 required no source changes to uses of output-response-like functions, but I didn't like communicating the value through a current-send-timeout parameter. Using a parameter required using parameterize around any context in which output-response might be called, which seemed error-prone—and indeed, #77 only parameterized current-send-timeout inside serve from web-server/web-server, so programs that used serve/web-config@ or used the unit layer directly, for example, wouldn't set the parameter.

Instead, I extend start-connection-manager to accept an optional safety-limits argument and cooperate with new-connection to put the timeout inside an extended connection struct. This approach also seems extensible to future kinds of limits that apply to the connection. The downside is that the basic connection struct is documented, but creating connections without going through new-connection would circumvent the safety limits. It isn't entirely satisfying, but anyone who is manipulating connection instances can already do lots of bad stuff, so I've just documented the added restriction.

(The basic connection struct is also mutable, though the mutability isn't documented, and exploiting that seems like it already could cause problems painful to contemplate: for now I just ignore it, but a future PR might try to limit the mutability or at least not provide all of the mutators.)

Configuration tables

How should configuration tables support safety-limits? In #77, Bogdanp@cefe99f extends configuration tables to support response-timeout and response-send-timeout, but not the other limits and timeouts. Here, I revert that change—some reasons are:

  • Configuration tables remain consistent with web-config^ (as opposed to the new web-config*^), rather than becoming a special case in which parts of safety-limits they support.
  • In general, I've tried to make public APIs deal with whole safety-limits values, even when they only use a few pieces of them, in the interest of maintaining a single point of control and the possibility of adding new pieces in the future.
  • Various mailing-list posts from @jeapostrophe suggest that the status of configuration tables is somewhere between "not recommended for new programs" and a sort of soft deprecation. For example: "You are right to use serve/servlet and friends rather than the
    configuration-table stuff, which is just there for backwards
    compatibility."

serve/servlet and serve/launch/wait

Before #77, these supported only a max-waiting argument, whereas serve and friends from web-server/web-server also accepted an initial-connection-timeout. Right now, I don't add an initial-connection-timeout argument to functions that didn't already accept it, because adding a deprecated argument feels a bit silly. On the other hand, I can see a case for making everything consistent with serve.

Miscellaneous

  • Should any higher-level modules reexport web-server/safety-limits?
  • Right now, I put the section documenting safety-limits in "Web Server: HTTP Server", §1 "Dispatching Servers", between "Dispatching Server Signatures" and "Dispatching Server Unit." I can think of various other places to put it: a new top-level section in "Web Server: HTTP Server"? In "Web Applications in Racket", since it's referenced there?

@Bogdanp Bogdanp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great so far! I agree with everything you've proposed and I'll do a local review once the final changes are ready to re-run the scenarios I went through in #77.

(lambda (in)
(let loop ([bindings null])
(match (match-query-key in)
(match (regexp-try-match #rx#"^([^=&]+)([=&]?)" in) ;; query key

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but I think the way this used to be was slightly clearer and it made it easier to test out the regexps in a REPL.

@jeapostrophe

Copy link
Copy Markdown
Contributor

Re: Configuration Tables --- There are A LOT of features that these do not support and they have not been maintained in a very very long time, easily a decade. I don't think we should remove the command line tool, but it doesn't have feature parity now and couldn't feasibly have it.

@LiberalArtist

Copy link
Copy Markdown
Contributor Author

I've pushed another batch of changes that are still broken. I'm aiming to wrap this up by the end of the week.

@LiberalArtist

Copy link
Copy Markdown
Contributor Author

It's looking like "the end of the week" was a bit overly optimistic, and I'm going to have limited connectivity for roughly the next week, but I should be able to finish not long after the new year.

@LiberalArtist

Copy link
Copy Markdown
Contributor Author

I am having a hard time debugging one last test failure. In the CI tests, I am getting the failure all-e2e-tests.rkt: raco test: non-zero exit: 1. The most detail I've managed to get locally is:

Sapientia:web-server philip$ raco test web-server-test/tests/web-server/e2e/all-e2e-tests.rkt
raco test: (submod "web-server-test/tests/web-server/e2e/all-e2e-tests.rkt" test)
raco test: @(test-responsible '(jay))
all-e2e-tests.rkt: raco test: test raised an exception

I am not sure how to figure out more precisely what is going wrong.

With some tweaks to "all-e2e-tests.rkt" so I can comment out some cases, it looks like the echo and tls e2e tests are working fine, but all of the others have problems—but I still haven't gotten an actual error message.

There is one more substantive commit for the revisions to binding:file, and it is essentially done: I'm just holding it until I can get these tests to pass.

@LiberalArtist

Copy link
Copy Markdown
Contributor Author

@Bogdanp

Bogdanp commented Jan 13, 2020

Copy link
Copy Markdown
Contributor

I am not sure how to figure out more precisely what is going wrong.

It's surprising that raco test doesn't report the exception. If I load the test submodule inside racket-mode, I get this exception:

; application: procedure does not expect an argument with given keyword
;   procedure: serve
;   given keyword: #:max-request-file-length
;   arguments...:
;    #:dispatch #<procedure:...patch-filter.rkt:12:0>
;    #:max-request-file-length 500
;    #:max-request-file-memory-threshold 250
;    #:max-request-files 2
;    #:port 9114
; Context:
;  /Users/bogdan/sandbox/web-server/web-server-test/tests/web-server/e2e/all-e2e-tests.rkt:41:6
;  /Applications/Racket v7.5/share/pkgs/rackunit-lib/rackunit/private/result.rkt:91:3
;  /Applications/Racket v7.5/share/pkgs/rackunit-lib/rackunit/private/test-suite.rkt:139:7
;  /Applications/Racket v7.5/share/pkgs/rackunit-lib/rackunit/private/test-suite.rkt:136:2
;  /Applications/Racket v7.5/share/pkgs/rackunit-lib/rackunit/private/test-suite.rkt:61:0 apply-test-suite
;  /Applications/Racket v7.5/share/pkgs/rackunit-lib/rackunit/text-ui.rkt:91:0 run-tests5
;  (submod "/Users/bogdan/sandbox/web-server/web-server-test/tests/web-server/e2e/all-e2e-tests.rkt" test):1:1 [running body]
; [Due to errors, REPL is just module language, requires, and stub definitions]

It looks like e2e/file-upload/server.rkt needs to be updated.

@Bogdanp

Bogdanp commented Jan 13, 2020

Copy link
Copy Markdown
Contributor

@LiberalArtist this patch gets the e2e tests passing.

Also, fix a few compatability issues, particularly with signatures.
Avoid exposing the mutator or unprotected constructors,
even via reflective operations, while preserving `binding:file`
as a transparent struct for compatability.
This version reflects commits starting with 66b79c8
by Jesse Alama, @mflatt, @Bogdanp, @aymanosman, @samth, and @jeapostrophe:

- Adds many new protections against malicious or misbehaving clients,
  which are controled with a new `safety-limits?` abstraction.

- Adds `response/empty` constructor.

- Fixes bugs with `dispatch/servlet` and HMAC-SHA1 signatures
  for id cookies.

- Allows bytes in addition to strings as arguments to
  `web-server/http/id-cookie` functions for consistency.
@LiberalArtist
LiberalArtist marked this pull request as ready for review January 13, 2020 15:30
@LiberalArtist

Copy link
Copy Markdown
Contributor Author

I think this is complete! (Finally!) Thanks @Bogdanp for walking me through how the new limits should work.

@Bogdanp

Bogdanp commented Jan 13, 2020

Copy link
Copy Markdown
Contributor

I've run the same attacks against this branch as I did against my own PR and I don't see any regressions, which is great! I also ran matchacha.ro's end-to-end test suite as well as played around with the website myself locally and everything is working fine. I'll do another pass over the changes and the new documentation in the morning, but this has a 👍 from me so far.

I'm not sure exactly what the branching process as part of a release is for this repo in particular, so I figured I'd ask: is there a chance that master will be released as part of Racket 7.6 before this is merged, thereby making this (safety-limits in particular) a backwards-incompatible change with regards to that release? How do we make sure that doesn't happen? It may make sense to remove my changes from the 7.6 release if this can't get merged into the release branch "in time."

cc @samth

@mflatt

mflatt commented Jan 13, 2020

Copy link
Copy Markdown
Member

Whatever was in master as of January 7 is currently slated for the release. The manager for this repo, @jeapostrophe, can have anything he thinks appropriate replace that default until January 15. After January 15, any change requires a discussion among the release managers.

It sounds like Jay should decide whether to revert some commits to avoid backward-incompatibility (for now) or add new commits to get things into long-term shape.

@jeapostrophe

Copy link
Copy Markdown
Contributor

I think that we should add these commits for the long-term, unless someone sees any big problems by tomorrow, in which case, we should revert and continue working on this path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants