Skip to content
Open
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
37 changes: 20 additions & 17 deletions 11/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,26 @@ http {
publickey = Nginx::Var.new.publickey
privatekey = Nginx::Var.new.privatekey

if arg_publickey && arg_publickey.match(publickey) || !arg_expires
Nginx.return Nginx::HTTP_FORBIDDEN
end

plaintext = "#{Nginx::Var.new.request_method}#{Nginx::Var.new.uri}#{arg_expires}#{publickey}"
hmac_sha1 = Digest::HMAC.digest(plaintext, privatekey, Digest::SHA1)
signature = Base64::encode(hmac_sha1)

if expires < Time.now.to_i
Nginx.return Nginx::HTTP_FORBIDDEN
end

if signature == arg_signature
Nginx.echo "Sucess"
else
Nginx.return Nginx::HTTP_FORBIDDEN
end
Nginx.return -> do
if arg_publickey && arg_publickey.match(publickey) || !arg_expires
Copy link
Author

Choose a reason for hiding this comment

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

ただ、上記の条件文でtrueになったとき、Nginx.returnでは処理をやめずに進んでしまい、おそらくこれは意図していないのではないかと思いました。

Copy link
Owner

Choose a reason for hiding this comment

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

確かに、最後以外の部分を変更した時にスルーしてしまうのは意図していないですね。

return Nginx::HTTP_FORBIDDEN
end

plaintext = "#{Nginx::Var.new.request_method}#{Nginx::Var.new.uri}#{arg_expires}#{publickey}"
hmac_sha1 = Digest::HMAC.digest(plaintext, privatekey, Digest::SHA1)
signature = Base64::encode(hmac_sha1)

if expires < Time.now.to_i
return Nginx::HTTP_FORBIDDEN
end

if signature == arg_signature
Nginx.echo "Sucess"
return Nginx::HTTP_OK
Copy link
Author

Choose a reason for hiding this comment

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

signatureをいじるとココの部分に到達すると思うので、これでステータスが戻るのは正常に見えます。

else
return Nginx::HTTP_FORBIDDEN
end
end.call
';
}
}
Expand Down