Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
scan_ruby:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

steps:
- name: Checkout code
Expand All @@ -25,7 +25,7 @@ jobs:
run: bin/bundler-audit

lint:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
env:
RUBOCOP_CACHE_ROOT: tmp/rubocop
steps:
Expand All @@ -51,7 +51,7 @@ jobs:
run: bin/rubocop -f github

test:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

services:
postgres:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/kamal-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permissions:

jobs:
kamal-run:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
timeout-minutes: 60

concurrency:
Expand Down
203 changes: 102 additions & 101 deletions Gemfile.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions app/controllers/concerns/paste_access.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ def paste_unlocked?(paste)
end

def require_paste_password!(paste, redirect: true)
if paste.suspicious?
response.headers["Cache-Control"] = "no-store"
render plain: "This paste is unavailable.", status: :forbidden
return false
end

return true if paste_unlocked?(paste)

if redirect
Expand Down
6 changes: 5 additions & 1 deletion config/bundler-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
# CVEs that are not relevant to the application can be enumerated on the ignore list below.

ignore:
- CVE-THAT-DOES-NOT-APPLY
# Affects outbound MCP::Client::OAuth discovery. This app only hosts an
# MCP::Server and uses Doorkeeper for inbound OAuth; it never creates an MCP
# client or performs SDK OAuth discovery. Revisit before adding an MCP client.
# https://github.com/modelcontextprotocol/ruby-sdk/security/advisories/GHSA-4m5j-jjfc-97gx
- GHSA-4m5j-jjfc-97gx
5 changes: 5 additions & 0 deletions db/migrate/20261111000000_add_suspicious_to_pastes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSuspiciousToPastes < ActiveRecord::Migration[8.1]
def change
add_column :pastes, :suspicious, :boolean, default: false, null: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 118 additions & 0 deletions test/controllers/suspicious_pastes_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
require "test_helper"

class SuspiciousPastesTest < ActionDispatch::IntegrationTest
setup do
@paste = Paste.create!(
content: "<title>Private marker</title><h1>Original content</h1>",
original_filename: "original.html",
custom_subdomain: "suspicious-test"
)
end

test "flag blocks every public content route and alias without recording views" do
@paste.update!(suspicious: true)

assert_no_difference "PasteView.count" do
public_urls.each do |url|
get url
assert_blocked

head url
assert_response :forbidden
assert_empty response.body
end
end
end

test "flag overrides cached responses and clearing it restores the original content" do
assert_not @paste.reload.suspicious?
original_content = @paste.content
original_updated_at = @paste.updated_at

public_urls.each do |url|
@paste.update_columns(suspicious: false)
get url
assert_response :success
etag = response.headers.fetch("ETag")

# Even a bulk flag update that leaves updated_at unchanged must block
# revalidation instead of returning 304 for a previously cached document.
@paste.update_columns(suspicious: true)
get url, headers: { "If-None-Match" => etag }
assert_blocked
end

@paste.update_columns(suspicious: false)
get raw_paste_url(@paste, host: "www.example.com")
assert_response :success
assert_equal original_content, response.body
assert_equal original_content, @paste.reload.content
assert_equal original_updated_at, @paste.updated_at
end

test "flag overrides password unlock sessions and valid preview tokens" do
@paste.update!(password: "sekret")
post paste_password_url(@paste), params: { password: "sekret" }
get paste_url(@paste)
assert_response :success
preview_url = css_select("iframe").first["src"]

# Leave the password access version intact, so these credentials remain valid.
@paste.update_columns(suspicious: true)
get paste_url(@paste)
assert_blocked
get preview_url
assert_blocked
end

test "owner access and web updates cannot clear the flag" do
@paste.update!(user: users(:alice), password: "sekret", suspicious: true)
post session_url, params: { email_address: users(:alice).email_address, password: "password" }

get raw_paste_url(@paste)
assert_blocked

patch owned_paste_url(@paste), params: {
suspicious: false,
file: fixture_file_upload("hello.html", "text/html")
}
assert_response :see_other
assert @paste.reload.suspicious?
assert_includes @paste.content, "Hello from a fixture"
get raw_paste_url(@paste)
assert_blocked
end

test "API republishing cannot clear the flag" do
@paste.update!(suspicious: true)

patch api_paste_url(@paste, suspicious: false),
params: "<h1>Republished</h1>",
headers: { "Content-Type" => "text/html", "Authorization" => "Bearer #{@paste.update_token}" }

assert_response :success
assert @paste.reload.suspicious?
assert_equal "<h1>Republished</h1>", @paste.content
get raw_paste_url(@paste)
assert_blocked
end

private
def public_urls
[ @paste.token, @paste.custom_subdomain ].flat_map do |identifier|
[
paste_url(identifier), raw_paste_url(identifier),
render_paste_url(identifier), markdown_paste_url(identifier),
"http://#{identifier}.example.com/"
]
end
end

def assert_blocked
assert_response :forbidden
assert_equal "This paste is unavailable.", response.body
assert_equal "text/plain", response.media_type
assert_equal "no-store", response.headers["Cache-Control"]
assert_nil response.headers["ETag"]
end
end
Loading