x 0.19.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -0
  3. data/CHANGELOG.md +648 -15
  4. data/README.md +506 -73
  5. data/SECURITY.md +66 -0
  6. data/UPGRADING.md +670 -0
  7. data/lib/x/version.rb +16 -1
  8. data/lib/x.rb +13 -1
  9. data/sig/manifest.yaml +5 -0
  10. data/sig/x.rbs +5 -361
  11. metadata +57 -49
  12. data/bin/console +0 -10
  13. data/bin/setup +0 -6
  14. data/lib/x/account_uploader.rb +0 -168
  15. data/lib/x/authenticator.rb +0 -21
  16. data/lib/x/bearer_token_authenticator.rb +0 -36
  17. data/lib/x/client.rb +0 -191
  18. data/lib/x/client_credentials.rb +0 -208
  19. data/lib/x/connection.rb +0 -183
  20. data/lib/x/errors/bad_gateway.rb +0 -6
  21. data/lib/x/errors/bad_request.rb +0 -6
  22. data/lib/x/errors/client_error.rb +0 -6
  23. data/lib/x/errors/connection_exception.rb +0 -6
  24. data/lib/x/errors/error.rb +0 -4
  25. data/lib/x/errors/forbidden.rb +0 -6
  26. data/lib/x/errors/gateway_timeout.rb +0 -6
  27. data/lib/x/errors/gone.rb +0 -6
  28. data/lib/x/errors/http_error.rb +0 -84
  29. data/lib/x/errors/internal_server_error.rb +0 -6
  30. data/lib/x/errors/invalid_media_type.rb +0 -6
  31. data/lib/x/errors/network_error.rb +0 -6
  32. data/lib/x/errors/not_acceptable.rb +0 -6
  33. data/lib/x/errors/not_found.rb +0 -6
  34. data/lib/x/errors/payload_too_large.rb +0 -6
  35. data/lib/x/errors/server_error.rb +0 -6
  36. data/lib/x/errors/service_unavailable.rb +0 -6
  37. data/lib/x/errors/too_many_redirects.rb +0 -6
  38. data/lib/x/errors/too_many_requests.rb +0 -58
  39. data/lib/x/errors/unauthorized.rb +0 -6
  40. data/lib/x/errors/unprocessable_entity.rb +0 -6
  41. data/lib/x/media_upload_validator.rb +0 -36
  42. data/lib/x/media_uploader.rb +0 -234
  43. data/lib/x/oauth2_authenticator.rb +0 -169
  44. data/lib/x/oauth_authenticator.rb +0 -182
  45. data/lib/x/rate_limit.rb +0 -89
  46. data/lib/x/redirect_handler.rb +0 -109
  47. data/lib/x/request_builder.rb +0 -93
  48. data/lib/x/response_parser.rb +0 -81
  49. data/lib/x/stream_parser.rb +0 -75
data/SECURITY.md ADDED
@@ -0,0 +1,66 @@
1
+ # Security Policy
2
+
3
+ ## Supported versions
4
+
5
+ `x`, `x-core`, `x-uploads`, `x-streams`, and `x-resources` are released from this repository in lockstep, at the
6
+ version in [VERSION](https://github.com/sferik/x-ruby/blob/main/VERSION). Security fixes are released for the latest 1.x
7
+ version of each gem. Versions before 1.0 are not supported;
8
+ [UPGRADING.md](https://github.com/sferik/x-ruby/blob/main/UPGRADING.md) covers what code written for 0.19 needs.
9
+
10
+ | Version | Supported |
11
+ | --- | --- |
12
+ | 1.x | ✅ |
13
+ | 0.x | ❌ |
14
+
15
+ ## Reporting a vulnerability
16
+
17
+ Report a vulnerability privately, with [Report a
18
+ vulnerability](https://github.com/sferik/x-ruby/security/advisories/new), rather than by opening an issue or a pull
19
+ request, which are public. Reports are acknowledged as soon as possible, and a fix is released with an advisory that
20
+ credits the reporter, unless the reporter asks otherwise.
21
+
22
+ Include what you can:
23
+
24
+ * which gem, and which version
25
+ * what an attacker can do, and what they need in order to do it
26
+ * the smallest script that shows the problem
27
+ * the Ruby version and platform you saw it on
28
+
29
+ A vulnerability in the X API itself, rather than in these gems, belongs to X, and should be reported to X rather
30
+ than here.
31
+
32
+ ## Handling credentials
33
+
34
+ The gems hold API keys, access tokens, and bearer tokens for as long as a client lives, and send them in the
35
+ `Authorization` header of every request. Four things are worth knowing:
36
+
37
+ * `X::Client#inspect` prints the base URL and the class of the authenticator, and no token or secret, so a client
38
+ is safe to log or to show in a backtrace. An OAuth 2.0 authenticator adds its client ID and expiration time, which
39
+ are not secret. A client, a streaming client, an authenticator, and an `X::OAuth2Authorization` raise `TypeError`
40
+ from `Marshal.dump`, `YAML.dump`, `as_json`, and `to_json` rather than write their credentials in the clear, so a
41
+ client held in a Hash is not cached with them, nor written with the arguments of a job a queue keeps as YAML, nor
42
+ rendered as JSON into a response or a log, and a resource or a page of them writes plain data to any of them
43
+ without the client it holds. The `X::OAuth2Tokens` that `save_tokens` is passed do marshal, and write themselves
44
+ as YAML, tokens and all, since they are what is stored; keep what they write where you would keep the tokens.
45
+ * `debug_output` is not. It writes every request and response to the IO it is given, headers included, so it writes
46
+ the `Authorization` header of each request, and the tokens in the body of an OAuth 2.0 token refresh. Send it to a
47
+ file you control, never to a log that is shipped elsewhere, and leave it unset in production.
48
+ * A client that is given no `proxy_url` takes the proxy the environment names, in `https_proxy` or `http_proxy`, as
49
+ most HTTP clients do. Requests then reach X through whatever that names: a proxy of an HTTPS request is asked to
50
+ tunnel it, so it sees the host and not the credentials, but one that terminates TLS, with a certificate the
51
+ process trusts, sees every header. Set `no_proxy`, or pass a `proxy_url` of your own, where the environment is not
52
+ yours to trust.
53
+ * A request that leaves the origin of the `base_url`, and a redirect that leads off it, is sent without the
54
+ `Authorization` header the authenticator signs and without any `Authorization`, `Cookie`, or
55
+ `Proxy-Authorization` header of the client or the request. Those three names are the whole of what is dropped. A
56
+ credential carried in a header of another name, such as one a gateway of your own reads, is sent wherever the
57
+ request goes, so pass it to the request that needs it rather than to `X::Client.new`, which sends the headers it
58
+ is given with every request the client makes.
59
+
60
+ An OAuth 2.0 refresh token is accepted once: a refresh returns a new one, and `save_tokens` is passed the
61
+ `X::OAuth2Tokens` of each refresh so that the new tokens can be stored. Dropping them leaves the stored refresh token
62
+ useless, and the user has to authorize the app again. A `save_tokens` that raises, as one whose store is
63
+ briefly down may, raises `X::TokenReportFailed`, whose `tokens` are the new ones, so they can be stored again.
64
+ Processes that share the tokens of a user pass `load_tokens` as well, so that a refresh reads the tokens another
65
+ process stored rather than spend a refresh token already spent. The authenticator keeps its access token and refresh
66
+ token private, as a client does, so neither reads off `client.authenticator`.