graph_attack 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +52 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.rubocop.yml +57 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.md +21 -0
- data/README.md +118 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/graph_attack.gemspec +42 -0
- data/lib/graph_attack/metadata.rb +4 -0
- data/lib/graph_attack/rate_limiter.rb +89 -0
- data/lib/graph_attack/version.rb +3 -0
- data/lib/graph_attack.rb +7 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 86f3e5cffd6d44474777d8922c3c4082d21143dd
|
4
|
+
data.tar.gz: 2a0ad09a08d65b22c3b97752b1ce0428cc2040e9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 830ea8dbf7fad402e69a27bc1e05189af0488fb241580e12a65bb69eca19591552411f4868cd657fd656d989a868686564c5791b0f250bded67e26ae17389d92
|
7
|
+
data.tar.gz: b7566c50d48645f92ad17bb2f5210346042c178bc10cbe91ea9d58514161570e364d898275b3dadee215588201372d2c38e78177318c10554b4760e523c91bfd
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
#
|
5
|
+
version: 2
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
docker:
|
9
|
+
- image: circleci/ruby:2.4.1-node-browsers
|
10
|
+
- image: redis
|
11
|
+
|
12
|
+
working_directory: ~/repo
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- checkout
|
16
|
+
|
17
|
+
# Download and cache dependencies
|
18
|
+
- restore_cache:
|
19
|
+
keys:
|
20
|
+
- v1-dependencies-{{ checksum "graph_attack.gemspec" }}
|
21
|
+
# fallback to using the latest cache if no exact match is found
|
22
|
+
- v1-dependencies-
|
23
|
+
|
24
|
+
- run:
|
25
|
+
name: install dependencies
|
26
|
+
command: |
|
27
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
28
|
+
|
29
|
+
- save_cache:
|
30
|
+
paths:
|
31
|
+
- ./vendor/bundle
|
32
|
+
key: v1-dependencies-{{ checksum "graph_attack.gemspec" }}
|
33
|
+
|
34
|
+
# Run tests!
|
35
|
+
- run:
|
36
|
+
name: run tests
|
37
|
+
command: |
|
38
|
+
mkdir /tmp/test-results
|
39
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
40
|
+
|
41
|
+
bundle exec rspec --format progress \
|
42
|
+
--format RspecJunitFormatter \
|
43
|
+
--out /tmp/test-results/rspec.xml \
|
44
|
+
--format progress \
|
45
|
+
$TEST_FILES
|
46
|
+
|
47
|
+
# Collect reports
|
48
|
+
- store_test_results:
|
49
|
+
path: /tmp/test-results
|
50
|
+
- store_artifacts:
|
51
|
+
path: /tmp/test-results
|
52
|
+
destination: test-results
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
DisplayCopNames: true
|
4
|
+
|
5
|
+
# Do not sort gems in Gemfile, since we are grouping them by functionality.
|
6
|
+
Bundler/OrderedGems:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
# Trailing commas are required on multiline method arguments.
|
10
|
+
Style/TrailingCommaInArguments:
|
11
|
+
EnforcedStyleForMultiline: comma
|
12
|
+
|
13
|
+
# Trailing commas are required in multiline arrays.
|
14
|
+
Style/TrailingCommaInArrayLiteral:
|
15
|
+
EnforcedStyleForMultiline: comma
|
16
|
+
|
17
|
+
# Trailing commas are required in multiline hashes.
|
18
|
+
Style/TrailingCommaInHashLiteral:
|
19
|
+
EnforcedStyleForMultiline: comma
|
20
|
+
|
21
|
+
# Allow indenting multiline chained operations.
|
22
|
+
Layout/MultilineMethodCallIndentation:
|
23
|
+
EnforcedStyle: indented
|
24
|
+
|
25
|
+
# Limit method length (default is 10).
|
26
|
+
Metrics/MethodLength:
|
27
|
+
Max: 15
|
28
|
+
|
29
|
+
# Do not require `# frozen_string_literal: true` at the top of every file.
|
30
|
+
FrozenStringLiteralComment:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
# Allow ASCII comments (e.g "…").
|
34
|
+
Style/AsciiComments:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
# Do not comment the class we create, since the name should be self explanatory.
|
38
|
+
Documentation:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
# Do not verify the length of the blocks in specs.
|
42
|
+
Metrics/BlockLength:
|
43
|
+
Exclude:
|
44
|
+
- spec/**/*
|
45
|
+
|
46
|
+
# Allow indenting multiline chained operations.
|
47
|
+
Layout/MultilineMethodCallIndentation:
|
48
|
+
EnforcedStyle: indented
|
49
|
+
|
50
|
+
# Prefer `== 0`, `< 0`, `> 0` to `zero?`, `negative?` or `positive?`,
|
51
|
+
# since they don't exist before Ruby 2.3 or Rails 5 and can be ambiguous.
|
52
|
+
Style/NumericPredicate:
|
53
|
+
EnforcedStyle: comparison
|
54
|
+
|
55
|
+
# Allow shorter argument names like `ip`.
|
56
|
+
Naming/UncommunicativeMethodParamName:
|
57
|
+
MinNameLength: 2
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at sunny@sunfox.org. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Fanny Cheung, Sunny Ripert
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# GraphAttack
|
2
|
+
|
3
|
+
[![CircleCI](https://circleci.com/gh/sunny/graph_attack.svg?style=svg)](https://circleci.com/gh/sunny/graph_attack)
|
4
|
+
|
5
|
+
GraphQL analyser for blocking & throttling.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
This gem adds a method to limit access to your GraphQL fields by IP:
|
10
|
+
|
11
|
+
```rb
|
12
|
+
QueryType = GraphQL::ObjectType.define do
|
13
|
+
name 'Query'
|
14
|
+
|
15
|
+
field :someExpensiveField do
|
16
|
+
rate_limit threshold: 15, interval: 60
|
17
|
+
|
18
|
+
# …
|
19
|
+
end
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
This would allow only 15 calls per minute by the same IP.
|
24
|
+
|
25
|
+
## Requirements
|
26
|
+
|
27
|
+
Requires [GraphQL Ruby](http://graphql-ruby.org/) and a running instance
|
28
|
+
of [Redis](https://redis.io/).
|
29
|
+
|
30
|
+
## Installation
|
31
|
+
|
32
|
+
Add these lines to your application's `Gemfile`:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
# GraphQL analyser for blocking & throttling by IP.
|
36
|
+
gem 'graph_attack'
|
37
|
+
```
|
38
|
+
|
39
|
+
And then execute:
|
40
|
+
|
41
|
+
```sh
|
42
|
+
$ bundle
|
43
|
+
```
|
44
|
+
|
45
|
+
Add the query analyser to your schema:
|
46
|
+
|
47
|
+
```rb
|
48
|
+
ApplicationSchema = GraphQL::Schema.define do
|
49
|
+
query_analyzer GraphAttack::RateLimiter.new
|
50
|
+
|
51
|
+
# …
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
Finally, make sure you add the current user's IP address as `ip:` to the
|
56
|
+
GraphQL context:
|
57
|
+
|
58
|
+
```rb
|
59
|
+
class GraphqlController < ApplicationController
|
60
|
+
def create
|
61
|
+
result = ApplicationSchema.execute(
|
62
|
+
params[:query],
|
63
|
+
variables: params[:variables],
|
64
|
+
context: {
|
65
|
+
ip: request.ip,
|
66
|
+
},
|
67
|
+
)
|
68
|
+
render json: result
|
69
|
+
end
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
## Development
|
74
|
+
|
75
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
76
|
+
`rake` to run the tests and the linter. You can also run `bin/console` for an
|
77
|
+
interactive prompt that will allow you to experiment.
|
78
|
+
|
79
|
+
## Versionning
|
80
|
+
|
81
|
+
We use [SemVer](http://semver.org/) for versioning. For the versions available,
|
82
|
+
see the tags on this repository.
|
83
|
+
|
84
|
+
## Releasing
|
85
|
+
|
86
|
+
To release a new version, update the version number in `version.rb`, and then
|
87
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
88
|
+
push git commits and tags, and push the `.gem` file to
|
89
|
+
[rubygems.org](https://rubygems.org).
|
90
|
+
|
91
|
+
## Contributing
|
92
|
+
|
93
|
+
Bug reports and pull requests are welcome on GitHub at
|
94
|
+
https://github.com/sunny/graph_attack. This project is intended to be a safe,
|
95
|
+
welcoming space for collaboration, and contributors are expected to adhere to
|
96
|
+
the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
97
|
+
|
98
|
+
## Code of Conduct
|
99
|
+
|
100
|
+
Everyone interacting in the GraphAttack project’s codebases, issue trackers,
|
101
|
+
chat rooms and mailing lists is expected to follow the
|
102
|
+
[code of conduct](https://github.com/sunny/graph_attack/blob/master/CODE_OF_CONDUCT.md).
|
103
|
+
|
104
|
+
## License
|
105
|
+
|
106
|
+
This project is licensed under the MIT License - see the
|
107
|
+
[LICENSE.md](https://github.com/sunny/graph_attack/blob/master/LICENSE.md)
|
108
|
+
file for details.
|
109
|
+
|
110
|
+
## Authors
|
111
|
+
|
112
|
+
- **Fanny Cheung** - [KissKissBankBank](https://github.com/KissKissBankBank)
|
113
|
+
- **Sunny Ripert** - [KissKissBankBank](https://github.com/KissKissBankBank)
|
114
|
+
|
115
|
+
## Acknowledgments
|
116
|
+
|
117
|
+
Hat tip to [Rack::Attack](https://github.com/kickstarter/rack-attack) for the
|
118
|
+
the name.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Bundler
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
# Rspec
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
task default: :spec
|
10
|
+
# Rubocop
|
11
|
+
require 'rubocop/rake_task'
|
12
|
+
RuboCop::RakeTask.new(:rubocop)
|
13
|
+
|
14
|
+
task default: %i[spec rubocop]
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'graph_attack'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require 'pry'
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'graph_attack/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'graph_attack'
|
7
|
+
spec.version = GraphAttack::VERSION
|
8
|
+
spec.authors = ['Fanny Cheung', 'Sunny Ripert']
|
9
|
+
spec.email = ['fanny@ynote.hk', 'sunny@sunfox.org']
|
10
|
+
|
11
|
+
spec.summary = 'GraphQL analyser for blocking & throttling'
|
12
|
+
spec.description = 'GraphQL analyser for blocking & throttling'
|
13
|
+
spec.homepage = 'https://github.com/sunny/graph_attack'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
# This gem is an analyser for the GraphQL ruby gem.
|
23
|
+
spec.add_dependency 'graphql', '>= 1.7.9'
|
24
|
+
|
25
|
+
# A Redis-backed rate limiter.
|
26
|
+
spec.add_dependency 'ratelimit', '>= 1.0.3'
|
27
|
+
|
28
|
+
# Loads local dependencies.
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
30
|
+
|
31
|
+
# Development tasks runner.
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
|
34
|
+
# Testing framework.
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
|
+
|
37
|
+
# CircleCI dependency to store spec results.
|
38
|
+
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.3'
|
39
|
+
|
40
|
+
# Ruby code linter.
|
41
|
+
spec.add_development_dependency 'rubocop', '~> 0.55'
|
42
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module GraphAttack
|
2
|
+
# Query analyser you can add to your GraphQL schema to limit calls by IP.
|
3
|
+
#
|
4
|
+
# ApplicationSchema = GraphQL::Schema.define do
|
5
|
+
# query_analyzer GraphAttack::RateLimiter.new
|
6
|
+
# end
|
7
|
+
#
|
8
|
+
class RateLimiter
|
9
|
+
class Error < StandardError; end
|
10
|
+
class RateLimited < GraphQL::AnalysisError; end
|
11
|
+
|
12
|
+
def initial_value(query)
|
13
|
+
{
|
14
|
+
ip: query.context[:ip],
|
15
|
+
query_rate_limits: [],
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(memo, visit_type, irep_node)
|
20
|
+
if rate_limited_node?(visit_type, irep_node)
|
21
|
+
data = rate_limit_data(irep_node)
|
22
|
+
|
23
|
+
memo[:query_rate_limits].push(data)
|
24
|
+
|
25
|
+
increment_rate_limit(memo[:ip], data[:key])
|
26
|
+
end
|
27
|
+
|
28
|
+
memo
|
29
|
+
end
|
30
|
+
|
31
|
+
def final_value(memo)
|
32
|
+
handle_exceeded_calls_on_queries(memo)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def increment_rate_limit(ip, key)
|
38
|
+
raise Error, 'Missing :ip value on the GraphQL context' unless ip
|
39
|
+
|
40
|
+
rate_limit(ip).add(key)
|
41
|
+
end
|
42
|
+
|
43
|
+
def rate_limit_data(node)
|
44
|
+
data = node.definition.metadata[:rate_limit]
|
45
|
+
|
46
|
+
data.merge(
|
47
|
+
key: "graphql-query-#{node.name}",
|
48
|
+
query_name: node.name,
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def handle_exceeded_calls_on_queries(memo)
|
53
|
+
rate_limited_queries = memo[:query_rate_limits].map do |limit_data|
|
54
|
+
next unless calls_exceeded_on_query?(memo[:ip], limit_data)
|
55
|
+
|
56
|
+
limit_data[:query_name]
|
57
|
+
end.compact
|
58
|
+
|
59
|
+
return unless rate_limited_queries.any?
|
60
|
+
|
61
|
+
queries = rate_limited_queries.join(', ')
|
62
|
+
RateLimited.new("Query rate limit exceeded on #{queries}")
|
63
|
+
end
|
64
|
+
|
65
|
+
def calls_exceeded_on_query?(ip, query_limit_data)
|
66
|
+
rate_limit(ip).exceeded?(
|
67
|
+
query_limit_data[:key],
|
68
|
+
threshold: query_limit_data[:threshold],
|
69
|
+
interval: query_limit_data[:interval],
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
def rate_limit(ip)
|
74
|
+
@rate_limit ||= {}
|
75
|
+
@rate_limit[ip] ||= Ratelimit.new(ip)
|
76
|
+
end
|
77
|
+
|
78
|
+
def rate_limited_node?(visit_type, node)
|
79
|
+
query_field_node?(node) &&
|
80
|
+
visit_type == :enter &&
|
81
|
+
node.definition.metadata[:rate_limit]
|
82
|
+
end
|
83
|
+
|
84
|
+
def query_field_node?(node)
|
85
|
+
node.owner_type.name == 'Query' &&
|
86
|
+
node.ast_node.is_a?(GraphQL::Language::Nodes::Field)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/graph_attack.rb
ADDED
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: graph_attack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fanny Cheung
|
8
|
+
- Sunny Ripert
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-09-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: graphql
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 1.7.9
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 1.7.9
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: ratelimit
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.0.3
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.0.3
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.15'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.15'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '10.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '10.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec_junit_formatter
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0.3'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0.3'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rubocop
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0.55'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0.55'
|
112
|
+
description: GraphQL analyser for blocking & throttling
|
113
|
+
email:
|
114
|
+
- fanny@ynote.hk
|
115
|
+
- sunny@sunfox.org
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".circleci/config.yml"
|
121
|
+
- ".gitignore"
|
122
|
+
- ".rspec"
|
123
|
+
- ".rubocop.yml"
|
124
|
+
- ".travis.yml"
|
125
|
+
- CODE_OF_CONDUCT.md
|
126
|
+
- Gemfile
|
127
|
+
- LICENSE.md
|
128
|
+
- README.md
|
129
|
+
- Rakefile
|
130
|
+
- bin/console
|
131
|
+
- bin/setup
|
132
|
+
- graph_attack.gemspec
|
133
|
+
- lib/graph_attack.rb
|
134
|
+
- lib/graph_attack/metadata.rb
|
135
|
+
- lib/graph_attack/rate_limiter.rb
|
136
|
+
- lib/graph_attack/version.rb
|
137
|
+
homepage: https://github.com/sunny/graph_attack
|
138
|
+
licenses: []
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.6.11
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: GraphQL analyser for blocking & throttling
|
160
|
+
test_files: []
|