Skip to content

Instantly share code, notes, and snippets.

@simonamor
simonamor / Request.pm
Created October 6, 2020 09:23
Patch for Catalyst::Request to allow reading body in begin() and still using body_data via Catalyst::Action::REST
diff -u Catalyst/Request.pm.orig Catalyst/Request.pm
--- Catalyst/Request.pm.orig 2020-10-06 10:17:47.549710876 +0100
+++ Catalyst/Request.pm 2020-10-06 10:17:31.352855930 +0100
@@ -130,6 +130,7 @@
if($match) {
my $fh = $self->body;
+ seek($fh,0,0);
local $_ = $fh;
return $self->data_handlers->{$match}->($fh, $self);
@simonamor
simonamor / MyApp.pm
Created September 14, 2020 11:08
partial content of MyApp.pm
package MyApp;
...
use Catalyst qw/
ConfigLoader
Static::Simple
Authentication
Authorization::Roles
@simonamor
simonamor / samesite.patch
Created August 7, 2020 14:46
Patch for Catalyst/Plugin/Session/State/Cookie.pm to add the SameSite header
--- Catalyst/Plugin/Session/State/Cookie.pm.orig 2020-08-07 15:40:56.855643211 +0100
+++ Catalyst/Plugin/Session/State/Cookie.pm 2020-08-07 11:53:35.131890154 +0100
@@ -81,6 +81,10 @@
$cookie->{httponly} = 1
unless defined $cookie->{httponly}; # default = 1 (set httponly)
+ $cookie->{samesite} = $cfg->{cookie_samesite};
+ $cookie->{samesite} = "Lax"
+ unless defined $cookie->{ samesite}; # default = Lax
+
@simonamor
simonamor / gitea.service
Created August 30, 2017 07:25
gitea systemd unit file
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
#After=mysqld.service
#After=postgresql.service
#After=memcached.service
#After=redis.service
[Service]
@simonamor
simonamor / managing users.txt
Created April 13, 2017 08:56
Login and Password reset notes
Rate limit login attempts - after 3 failures, include a captcha
When prompting for the username/email address, provide the same response if the username exists as if it doesn't exist. "An email has been sent to x---@y----.--- with instructions" This prevents username enumeration.
Token generation - create a token, send it by email and store a HASHED version of the token (plain SHA-2 is sufficient) in the database.
Token should expire within 2 hours, perhaps only 30 minutes.
The email should include:
- a link to the password reset page to get a new token if the old one has expired
- the requestors IP address
@simonamor
simonamor / auto-deploy.pl
Last active February 28, 2017 13:06
auto-deploying a database schema from catalyst app
use DBIx::Class::DeploymentHandler;
# (removed standard Catalyst app module stuff)
# Start the application
__PACKAGE__->setup();
my $model = __PACKAGE__->model('DB');
my $dh = DBIx::Class::DeploymentHandler->new({
schema => $model->schema,
@simonamor
simonamor / id_or_foo_id.pl
Created November 21, 2016 13:55
->id created as accessor even though no id column - feature? bug?
{
package SomeResult;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table("foo");
__PACKAGE__->add_columns(
foo_id => {
data_type => "integer",
@simonamor
simonamor / build.log
Created October 25, 2016 19:29
Devel::CheckOS build.log from cpanm
cpanm (App::cpanminus) 1.7040 on perl 5.020001 built for x86_64-linux
Work directory is /home/cat/.cpanm/work/1477423518.6044
You have make /usr/bin/make
You have LWP 6.15
You have /bin/tar: tar (GNU tar) 1.23
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
@simonamor
simonamor / Root.pm
Last active September 14, 2016 10:32
Working Catalyst Chained dispatch example
package MyApp::Controller::Root;
use Moose;
use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller' }
__PACKAGE__->config(namespace => '');
sub chain_root :Chained('/') :PathPart('') :CaptureArgs(0) {
my ($self,$c) = @_;
package MyApp::Base;
sub new {
my $class = shift;
my $self = { abc => "def", xyz => "123" };
bless $self, $class;
return $self;
}
sub get_abc {