<commit_before># Rack::RestrictAccess

Compares env 'REMOTE_ADDR' and 'PATH_INFO' against user-defined values to _block_ (403), _restrict_ (401 basic auth), or _allow_ access to the rack app.

Intended for use in simple access control. Should not be considered a security solution.

## Installation

Add this line to your application's Gemfile:

    gem 'rack-restrict_access'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install rack-restrict_access

## Usage

Include in application.rb

```
# /config/application.rb

module ApplicationName
  class Application < Rails::Application

    ...

    config.middleware.use Rack::RestrictAccess do
      restrict do
        all_resources!
        # single/multiple delimited string(s), regexp(s), or array(s) of both
        credentials ENV['RESTRICTED_ACCESS_CREDENTIALS'], :delimiter => ","
      end

      # single/multiple delimited string(s), regexp(s), or array(s) of both
      allow do
        origin_ips ENV['ALLOWED_IPS'], "0.0.0.0", /192.168.\d{1}.\d.\d{1}$/, :delimiter => ","
      end
    end

    ...

  end
end
```

### DSL

There are three kinds of filters: `block`, `restrict`, and `allow`. They apply to `resources` (site paths) and `origin_ips` (REMOTE_ADDR/IP of requester), which the user designates.

#### `restrict`

Enforces HTTP Authentication for items passed through a block.

```
# require login the entire site

restrict do
  all_resources!
end
```

```
# restrict access to the specific path "/secret-place", and paths starting with "/admin"

restrict do
  resources /^\/admin\/.*/, "/secret-place"
  # also supports array(s) of strings/regexps
  # use :delimiter => STRING/REGEXP for delimited strings (also applies to strings in arrays)
end
```

```
#restrict access to any part of the site for the follolowing IPs

restrict do
  origin_ips "192.168.1.1,192.168.127.12", :delimiter => ","  # or Regexps
end
```

```
#or both!

restrict do
  # block access to the specific path "/secret-place", and paths starting with "/admin"
  resources /^\/admin\/*/, "/secret-place"

  # also block access to anything for these IPs:
  origins "192.168.1.1", "192.168.127.12"
end
```

##### Credentials

Designate one or multiple valid username/password combinations.


```
restrict do
  all_resources!

  #delimiter options required if dealing with delimited strings:

  credentials "st<PASSWORD>:<PASSWORD>|<PASSWORD>:<PASSWORD>" :credentials_delimiter => ":", :credential_pair_delimiter => "|"

  #delimiter options default to :credentials => "," and :credential_pair_delimiter => ";" , respectively
end
```

#### `block`

Returns _403 FORBIDDEN_ for items passed through a block. Use same as `restrict`.

```
# block all the things!
block do
  all_resources!
end
```

```
block do
  # block access to the specific path "/secret-place", and paths starting with "/admin"

  resources /^\/admin\/*/, "/secret-place"

  # also supports array(s) of strings/regexps
  # use :delimiter => STRING/REGEXP for delimited strings (also applies to strings in arrays)

  # also block access to anything for these IPs:
  origin_ips "192.168.1.1", "192.168.127.12"
end

```<commit_msg>add credentials details<commit_after># Rack::RestrictAccess

Compares env 'REMOTE_ADDR' and 'PATH_INFO' against user-defined values to _block_ (403), _restrict_ (401 basic auth), or _allow_ access to the rack app.

Intended for use in simple access control. Should not be considered a security solution.

## Installation

Add this line to your application's Gemfile:

    gem 'rack-restrict_access'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install rack-restrict_access

## Usage

Include in application.rb

```
# /config/application.rb

module ApplicationName
  class Application < Rails::Application

    ...

    config.middleware.use Rack::RestrictAccess do
      restrict do
        all_resources!
        # single/multiple delimited string(s), regexp(s), or array(s) of both
        credentials ENV['RESTRICTED_ACCESS_CREDENTIALS'], :delimiter => ","

      end

      # single/multiple delimited string(s), regexp(s), or array(s) of both
      allow do
        origin_ips ENV['ALLOWED_IPS'], "0.0.0.0", /192.168.\d{1}.\d.\d{1}$/, :delimiter => ","
      end
    end

    ...

  end
end
```

### DSL

There are three kinds of filters: `block`, `restrict`, and `allow`. They apply to `resources` (site paths) and `origin_ips` (REMOTE_ADDR/IP of requester), which the user designates.

#### `restrict`

Enforces HTTP Authentication for items passed through a block.

```
# require login the entire site

restrict do
  all_resources!
end
```

```
# restrict access to the specific path "/secret-place", and paths starting with "/admin"

restrict do
  resources /^\/admin\/.*/, "/secret-place"
  # also supports array(s) of strings/regexps
  # use :delimiter => STRING/REGEXP for delimited strings (also applies to strings in arrays)
end
```

```
#restrict access to any part of the site for the follolowing IPs

restrict do
  origin_ips "192.168.1.1,192.168.127.12", :delimiter => ","  # or Regexps
end
```

```
#or both!

restrict do
  # block access to the specific path "/secret-place", and paths starting with "/admin"
  resources /^\/admin\/*/, "/secret-place"

  # also block access to anything for these IPs:
  origins "192.168.1.1", "192.168.127.12"
end
```

##### Credentials

Designate one or multiple valid username/password combinations. Can be single/multiple delimited strings, hashes (where :username and :password are set to a string or regexp), or arrays of strings


```
restrict do
  all_resources!

  #delimiter options required if dealing with delimited strings:
  credentials "stewie:coolwhip|brian:novel" :credentials_delimiter => ":", :credential_pair_delimiter => "|"

  #delimiter options default to :credentials => "," and :credential_pair_delimiter => ";" , respectively

  #or single/multiple hashes:
  credentials :username => "admin", :password => "<PASSWORD>"
end
```

#### `block`

Returns _403 FORBIDDEN_ for items passed through a block. Use same as `restrict`.

```
# block all the things!
block do
  all_resources!
end
```

```
block do
  # block access to the specific path "/secret-place", and paths starting with "/admin"

  resources /^\/admin\/*/, "/secret-place"

  # also supports array(s) of strings/regexps
  # use :delimiter => STRING/REGEXP for delimited strings (also applies to strings in arrays)

  # also block access to anything for these IPs:
  origin_ips "192.168.1.1", "192.168.127.12"
end

```
{'fraction_non_alphanumeric': 0.1229383017715333, 'fraction_numerical': 0.023824068417837508, 'mean_word_length': 3.7217015140591205, 'pattern_counts': {'":': 2, '<': 10, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 14, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '433557', 'n_tokens_mistral': 2199, 'n_tokens_neox': 2009, 'n_words': 707}